react-router icon indicating copy to clipboard operation
react-router copied to clipboard

[Bug]: NavLink is never active when using relative="path"

Open manzano78 opened this issue 2 years ago • 1 comments

What version of React Router are you using?

6.4.2

Steps to Reproduce

  1. Create a data router with one route configured with this path: /contact/:id
  2. In that route's element, render a relative="path" NavLink: <NavLink relative="path" to="../1" className={({ isActive }) => isActive ? "active" : undefined} >Michael</NavLink>
  3. In your browser, go to the following URL: /contact/1

Expected Behavior

The generated DOM element should contain the active class: <a href="/contact/1" class="active">Michael</a>

Actual Behavior

The generated DOM element has the right href but doesn't contain the active class: <a href="/contact/1">Michael</a>, so the expected styles aren't applied.

manzano78 avatar Oct 12 '22 15:10 manzano78

Looks like <NavLink> was not updated to handle <Link relative/> https://github.com/remix-run/react-router/blob/d9d233c7fbb6f712915e8b0a7c916a69064bfdb9/packages/react-router-dom/index.tsx#L430

kiliman avatar Oct 12 '22 16:10 kiliman

Merged the fix for this - should be released in a 6.4.3 hopefully later this week 👍

brophdawg11 avatar Oct 17 '22 14:10 brophdawg11

👋 Just did a prerelease (6.4.3-pre.0) which should fix this if you want to give it a shot!

brophdawg11 avatar Oct 21 '22 22:10 brophdawg11