我正在玩弄material-ui。我使用路线实现了 LeftNav,但找不到使用 IconMenu 或使用链接或路线的菜单的方法。任何人都可以给我指出一个好的来源/教程吗?文档不足,并且两个组件似乎都不支持“menuItems”作为属性,如 LeftNav 那样。
最佳答案
另一个迟来的更新:
containerElement
不再支持 prop,请使用 component
改为 Prop 。
查看文档here .
<小时/>2016 年 12 月编辑: linkButton
prop 已已弃用,您将收到警告:
Warning: Unknown props `linkButton` on <a> tag.
因此只需删除该 Prop 即可:
<MenuItem
containerElement={<Link to="/profile" />}
primaryText="Profile"
leftIcon={
<FontIcon className="material-icons">people</FontIcon>
}
/>
Here's an Example Repo ,和the Live Demo Here .
<小时/>原始答案:
只是想指出,如果您使用react-router,您可能需要使用<Link to="/some/page" />
而不是<a>
标签。
为此,您需要使用 containerElement
Prop
<MenuItem
linkButton
containerElement={<Link to="/profile" />}
primaryText="Profile"
leftIcon={
<FontIcon className="material-icons">people</FontIcon>
}
/>
(如果您只传递 ={true}
,则可以省略 true
,
换句话说,<MenuItem linkButton />
与 <MenuItem linkButton={true} />
相同)
containerElement
和linkButton
props 实际上已记录 in the buttons section ,但您可以在 MenuItem
中使用它也是如此。
关于reactjs - 使用路线的 Material UI 菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32106513/