Answer the question
In order to leave comments, you need to log in
Navlink how to change clicked link color?
I want that when I click on a link, its color changes and stays the same. But after clicking on another one, it changed color, and the previous link again became the same.
jsx:
<nav className={classes.nav}>
<div className={classes.item}>
<NavLink to="/profile" activeClassName={classes.active}>Profile</NavLink>
</div>
<div className={classes.item}>
<NavLink to="/dialogs"activeClassName={classes.active}>Messages</NavLink>
</div>
</nav>
.nav {
grid-area: n;
background-color: lightslategrey;
}
.item a {
color: white;
font-size: 25px;
}
Answer the question
In order to leave comments, you need to log in
I understand that you have version 6 of the router. Now you need to do this
<NavLink
to="/profile"
- activeClassName={classes.active}
+ className={({ isActive }) => (isActive ? classes.active : '')}
>
Messages
</NavLink>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question