React Router Dom v6 shows active for index as well as other subroutes

You can specify the end prop on the “root”-level link to the "/dashboard" path.

NavLink

If the end prop is used, it will ensure this component isn’t matched
as “active” when its descendant paths are matched.

<NavLink to='' end>
  {({ isActive }) =>
     isActive ? (
           <text style={{color: blue}}>Home</text>
     ) : (                      
           <text>Home</text>
     )
  }
</NavLink>

Edit react-router-dom-v6-shows-active-for-index-as-well-as-other-subroutes

Leave a Comment