Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Active class in react router

Hi I am using react router v6 and I use NavLink to navigate from one component to another component. I want to add custom active class in NavLink how can I achieve in react router v6. I use this but its not working.

<NavLink className="px-3 py-2 bg-primary" to={"/"} activeClassName="btn-group-active" >
Home
</NavLink >

How to achieve above with react router v6.

I got my answer from this link.

Active link with React-Router?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

<NavLink className={({ isActive }) => isActive ? "btn-group-active" : "bg-primary"} />

Refer the Docs

about 4 years ago · Juan Pablo Isaza Report

0

You can achieve this by doing that:

<NavLink
  to={customPath}
  className={({ isActive }) => (isActive ? "myCssClass" : "")}
>
  <Home />
</NavLink>

If you have further classes you concat them like that:

<NavLink
  to={customPath}
  className={({ isActive }) => (isActive ? "myActiveClass defaultClass defaultClassTwo" : "defaultClass")}
>
  <Home />
</NavLink>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!