Skip to content

React Router Fixing NavLink isActive For Parent Route

Jason Lewis edited this page Apr 26, 2023 · 1 revision

Up

Issue

When using nested routes and NavLink, the NavLink for the parent route is flagged as active as well as the current route.

Fix

Add the "end" attribute to the NavLink tag.

e.g.
<NavLink to="some/where" end>Go Somewhere</NavLink>

Clone this wiki locally