Dima Malko
Dima Malko

Reputation: 293

Change className of Link based on current URL, React

I have Sidebar component with Links, and i need to change Link color when specific URL is opened.

What is best solution of this in React?

Upvotes: 2

Views: 507

Answers (1)

Boussadjra Brahim
Boussadjra Brahim

Reputation: 1

You could use NavLink component and provide your class as value of activeClassName prop :

 <NavLink to="/faq" activeClassName="selected">
   FAQs
  </NavLink>

CSS rule could be like :

  .selected{
    color: blue
   }

Upvotes: 5

Related Questions