【问题标题】:semantic-ui-react dropdown link to a url指向 url 的语义 ui-react 下拉链接
【发布时间】:2018-11-17 20:14:13
【问题描述】:

我有一个 Semantic UI React Dropdown 组件,其中包含类似的选项

const options = [
  { key: 'user', text: 'Account', icon: 'user' },
  { key: 'settings', text: 'Settings', icon: 'settings' },
  { key: 'sign-out', text: 'Sign Out', icon: 'sign out' },
]

我想将上述每个项目链接到一个 url,例如“/account”、“/settings”和“/logout”

我不确定如何触发此类操作。我没有看到任何 href 或道具。我猜我将不得不编写一个 onClick 或 onChange 函数?

【问题讨论】:

    标签: dropdown semantic-ui-react


    【解决方案1】:

    简单的任务,不使用 onChange 改变路线:

    import { Link } from 'react-router-dom';
    
    const options = [
      { key: 'user', text: 'Account', icon: 'user', as: Link, to: '/my-account' },
      { key: 'settings', text: 'Settings', icon: 'settings' },
      { key: 'sign-out', text: 'Sign Out', icon: 'sign out' },
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-26
      • 1970-01-01
      • 2017-07-17
      相关资源
      最近更新 更多