Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I style active Link in react-router v4?

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?

like image 537
Ramtin Khalatbari Avatar asked Feb 04 '17 18:02

Ramtin Khalatbari


People also ask

How do I change the color of my active link in React?

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.


2 Answers

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

like image 115
Sergey Reutskiy Avatar answered Sep 19 '22 16:09

Sergey Reutskiy


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> 
like image 34
Gapur Kassym Avatar answered Sep 23 '22 16:09

Gapur Kassym