React Router V4 Implement NavLink inside a ListItem using Material UI

偶尔善良 提交于 2019-12-06 07:53:15

You can do it by setting the NavLink as the component of the list item. Here is an example that has worked for me!

<ListItem
  button
  key="Dashboard"
  component={NavLink} to="/dashboard"
>
    <ListItemIcon>
        <Dashboard />
    </ListItemIcon>
    <ListItemText primary="Dashboard" />
</ListItem>

Hope it helps!

You can attach a class to NavLink with something like:

<NavLink to="/" className="nav-link-item">
  Dashboard
</NavLink>

Then, attach styling to this class as:

.nav-link-item {
  color: inherit;
  text-decoration: none;
}

.nav-link-item:hover,
.nav-link-item:active,
.nav-link-item:visited {
  color: red;
  text-decoration: none;
}

/* Styling for when the link is active */
.nav-link-item.active {
  color: green;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!