【问题标题】:Handling clicks on a List of menu items in React and material-ui在 React 和 material-ui 中处理对菜单项列表的点击
【发布时间】:2017-12-18 21:50:38
【问题描述】:

我在 React 中有一个菜单组件,它利用了 Material-ui 列表组件,看起来像这样:

handleMenuItemClick() {
    // go to route defined in the ListItem
}

class MenuList extends React.Component {
    render() {
        return (
            <div>
                <List
                    onClick={this.handleMenuItemClick}
                >
                    <ListItem button route="/dashboard">
                        <DashboardIcon /> <ListItemText primary="Dashboard" />
                    </ListItem>
                    <ListItem button route="/investments">
                        <InvestmentsIcon /> <ListItemText primary="My investments" />
                    </ListItem>
                </List>
            </div>
        );
    }
}

我想要做的是去不同的路线定义ListItem的路线属性。我如何在 React 中做到这一点?

我不希望每个菜单项都有单独的点击处理程序。

【问题讨论】:

标签: javascript reactjs


【解决方案1】:
import {Link} from 'react-router-dom'
                       <ListItem
                            component={Link}
                            to="/"
                            button >

引用自 here

【讨论】:

  • 谢谢,比我想象的还要好
猜你喜欢
  • 2021-02-02
  • 2018-02-09
  • 2022-12-22
  • 1970-01-01
  • 2019-10-18
  • 1970-01-01
  • 2015-07-05
  • 2019-08-07
  • 1970-01-01
相关资源
最近更新 更多