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

Ramtin Khalatbari picture Ramtin Khalatbari · Feb 4, 2017 · Viewed 81.6k times · Source

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?

Answer

Sergey Reutskiy picture Sergey Reutskiy · Feb 5, 2017

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