react-router
react-router copied to clipboard
[Bug]: NavLink is never active when using relative="path"
What version of React Router are you using?
6.4.2
Steps to Reproduce
- Create a data router with one route configured with this path:
/contact/:id
- In that route's element, render a relative="path" NavLink:
<NavLink relative="path" to="../1" className={({ isActive }) => isActive ? "active" : undefined} >Michael</NavLink>
- 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.
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
Merged the fix for this - should be released in a 6.4.3 hopefully later this week 👍
👋 Just did a prerelease (6.4.3-pre.0
) which should fix this if you want to give it a shot!