<Link> with additional props for styling active and pending states.
Type Declaration
Props
Inherits all props from<Link>, with the following differences:
Classes are automatically applied to NavLink that correspond to the state:Or specify a function that receives render props:
Styles can be applied statically or dynamically via a function:
Can be regular React children or a function that receives render props:
Changes the matching logic for the active and pending states to only match to the “end” of the to path.
| Link | URL | isActive |
|---|---|---|
<NavLink to="/tasks" /> | /tasks | true |
<NavLink to="/tasks" /> | /tasks/123 | true |
<NavLink to="/tasks" end /> | /tasks | true |
<NavLink to="/tasks" end /> | /tasks/123 | false |
<NavLink to="/" /> is an exceptional case because every URL matches /. To avoid this matching every single route by default, it effectively ignores the end prop and only matches when you’re at the root route.Changes the matching logic to make it case-sensitive:
| Link | URL | isActive |
|---|---|---|
<NavLink to="/SpOnGe-bOB" /> | /sponge-bob | true |
<NavLink to="/SpOnGe-bOB" caseSensitive /> | /sponge-bob | false |
Examples
Basic Active Styling
With className Function
With style Function
With children Function
Vertical Navigation
Breadcrumbs
Behavior
- Automatically applies
aria-current="page"to the link when it’s active - The
isActivestate indicates if the link’s URL matches the current location - The
isPendingstate is only available in Framework and Data modes and indicates if the pending location matches the link’s URL - The
isTransitioningstate indicates if a view transition to the link’s URL is in progress - Default class names (
active,pending,transitioning) are applied automatically
Notes
isPendingis only available when using a data router (Framework or Data mode)- Root links (
to="/") always useendbehavior to avoid matching every route - Inherits all other props from
<Link>includingprefetch,replace,state, etc.