如何使用 material-ui@next MenuItem 进行路由?

IT技术 reactjs material-ui react-router-dom
2021-04-24 16:14:24

使用material-ui@next?实现路由的最佳实践是什么?在以前的版本中,我可以使用containerElementaLink但不再工作了。在文档中找不到任何帮助。

 <MenuItem containerElement={<Link to="/myRoute" />}>My Link</MenuItem>
2个回答

你现在可以MenuItem像这样一个组件props:

<MenuItem component={Link} to='/myRoute'>
go to my route
</MenuItem>

您可以Link用作父组件MenuItem

  <MenuList>
    <Link to="/myRoute" style={{ textDecoration: 'none', display: 'block' }}>
      <MenuItem>
        go to my route
      </MenuItem>
    </Link>
    <Link to="/anotherRoute" style={{ textDecoration: 'none', display: 'block' }}>
      <MenuItem>
        go to another route
      </MenuItem>
    </Link>
  </MenuList>