Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render Link in material ui Drawer

I want to add my react-router links to Drawer. I tried this:

<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>

My problem is that the link will render underlined (like the image below).

enter image description here

like image 581
alisabzevari Avatar asked Dec 03 '22 23:12

alisabzevari


2 Answers

I had similar concerns with using styles directly and came across the following answer: https://stackoverflow.com/a/48252439/522859

To summarize, use the component attribute on the ListItem:

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

The official docs cover it here: https://material-ui.com/api/list-item/

like image 58
Chris Owens Avatar answered Dec 08 '22 06:12

Chris Owens


Use inline style textDecoration: 'none' for the link. <Link> gets rendered as a standard <a> tag, which is why we can apply textDecoration rule there.

<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>
like image 45
Shubham Khatri Avatar answered Dec 08 '22 06:12

Shubham Khatri