材质 ui 抽屉中的渲染链接

IT技术 reactjs react-router material-ui
2021-05-26 09:11:47

我想将我的 react-router 链接添加到Drawer. 我试过这个:

<Drawer width={200} open={this.state.drawerOpen} docked={false} onRequestChange={this.toggleDrawer}>
   <Link to="/businesspartners">
      <MenuItem onTouchTap={this.toggleDrawer.bind(this, false)}
                rightIcon={<CommunicationBusiness />}
      >
         Business Partners
      </MenuItem>
   </Link>
</Drawer>

我的问题是链接将呈现下划线(如下图所示)。

在此处输入图片说明

3个回答

我对直接使用样式也有类似的担忧,并遇到了以下答案:https : //stackoverflow.com/a/48252439/522859

总而言之,使用 ListItem 上的组件属性:

<List>
   <ListItem button component={Link} to="https://www.google.com">
        <ListItemText primary="Google" />
   </ListItem>
</List>

官方文档在这里介绍:https : //material-ui.com/api/list-item/

textDecoration: 'none' 对链接使用内联样式 <Link>被呈现为标准<a>标签,这就是我们可以在那里应用 textDecoration 规则的原因。

<Drawer width={200} open={this.state.drawerOpen} docked={false} onRequestChange={this.toggleDrawer}>
   <Link to="/businesspartners" style={{ textDecoration: 'none' }}>
      <MenuItem onTouchTap={this.toggleDrawer.bind(this, false)}
                rightIcon={<CommunicationBusiness />}
      >
         Business Partners
      </MenuItem>
   </Link>
</Drawer>

我遇到了同样的问题,但可能由于这个原因在 materialUI 中的新更新不起作用,有一些调整,如 import from import Link from '@material-ui/core/Link';

所以它会起作用

     import Link from '@material-ui/core/Link';

     <List>
      <ListItem button component={Link} href="/dsda">
        <ListItemIcon>
          <DashboardIcon />
        </ListItemIcon>
        <ListItemText primary="DashBoard"/>
      </ListItem>
     </List>