In react-router v3 we had activeStyle and activeClassName to style active Link
we could do something like this
<div id="tags-container"> {tags.map(t => <Link className="tags" activeStyle={{ color: 'red' }} to={t.path} > {t.title} </Link> )} </div>
I wanna know how can I do same thing in v4?
How do I change the color of my active link in React? Highlight current nav link in react. inline style to change background color react. In React Router v6, activeStyle will be removed and you should use the function style to apply inline styles to either active or inactive NavLink components.
Use NavLink instead Link. Its not documented, but its work as you expect. https://github.com/ReactTraining/react-router/issues/4318
UPDATE 17.05.2017:
https://reacttraining.com/react-router/web/api/NavLink
You can do it with NavLink
in react-router
v4
<div id="tags-container"> {tags.map(t => <NavLink className="tags" activeStyle={{ color: 'red' }} to={t.path} > {t.title} </NavLink> )} </div>
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