I am new to React and I created a simple application with Login and Dashboard page. I have successfully configured my Public Routes and Private Routes with Redirect functionalities. However when I want to implement material-ui/core Things are still quite working well but I can't achieve the UI that I want.
Here is my old implementation of my NavBar below:
const Navigation = () => {
return (
<div>
<NavLink exact to="/" activeStyle={{ color: 'red' }}>Home</NavLink>
<NavLink to="/about" activeStyle={{ color: 'red' }}>About</NavLink>
<NavLink to="/contact" activeStyle={{ color: 'red' }}>Contact</NavLink>
</div>
)
}
export default Navigation
As simple as that with no styling or classes
But since I want to add some styles I used material/ui core and ended up doing the new one below:
export const MainNavigation = (
<div>
<ListItem button>
<ListItemIcon>
<DashboardIcon />
</ListItemIcon>
<ListItemText primary="Dashboard" />
</ListItem>
<ListItem button>
<ListItemIcon>
<ShoppingCartIcon />
</ListItemIcon>
<ListItemText primary="Orders" />
</ListItem>
<ListItem button>
<ListItemIcon>
<PeopleIcon />
</ListItemIcon>
<ListItemText primary="Customers" />
</ListItem>
<ListItem button>
<ListItemIcon>
<BarChartIcon />
</ListItemIcon>
<ListItemText primary="Reports" />
</ListItem>
<ListItem button>
<ListItemIcon>
<LayersIcon />
</ListItemIcon>
<ListItemText primary="Integrations" />
</ListItem>
</div>
);
Now the first ListItem
looks like this below:
But when I add this line of code below:
<ListItemText primary={<NavLink exact to="/">Dashboard</NavLink>} />
This is the result:
But I don't want this to happen.
I want to keep the first UI I dont wan't it to make it look like an anchor tag with a under line below
How can I also handle the active state of the ListItem
in material/ui integrated with react router NavLink
or Link
? So that I can put some style or uses the active class of material.
Appreciate if someone could help. Thanks in advance.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With