小编典典

使用路线的材料UI菜单

reactjs

我在玩Material-
ui。我使用路线实现了LeftNav,但找不到找到IconMenu或Menu来处理链接或路线的方法。任何人都可以为我指出一个好的资源/教程吗?该文档不足,并且两个组件似乎都不像LeftNav那样支持’menuItems’作为属性。


阅读 220

收藏
2020-07-22

共1个答案

小编典典

2016年12月编辑:linkButton道具已 弃用 ,您会收到警告:

Warning: Unknown props `linkButton` on <a> tag.

因此,只需删除道具:

<MenuItem
  containerElement={<Link to="/profile" />}
  primaryText="Profile"
  leftIcon={
    <FontIcon className="material-icons">people</FontIcon>
  }
/>

这是示例存储库,以及此处的实时演示


原始答案:

只是想指出,如果您使用的是react-router,则可能要使用<Link to="/some/page" />而不是<a>标签。

为此,您需要使用containerElement道具

<MenuItem
  linkButton
  containerElement={<Link to="/profile" />}
  primaryText="Profile"
  leftIcon={
    <FontIcon className="material-icons">people</FontIcon>
  }
/>

={true}如果您仅通过true<MenuItem linkButton />即与相同,则可以省略<MenuItem linkButton={true} />

containerElementlinkButton道具其实是记录在按键部分,但你可以用它MenuItem为好。

2020-07-22