<Link> with additional props for styling active and pending states.
Type Declaration
Props
Inherits all props from<Link>, with the following differences:
string | ((props: NavLinkRenderProps) => string)
Classes are automatically applied to NavLink that correspond to the state:Or specify a function that receives render props:
React.CSSProperties | ((props: NavLinkRenderProps) => React.CSSProperties)
Styles can be applied statically or dynamically via a function:
React.ReactNode | ((props: NavLinkRenderProps) => React.ReactNode)
Can be regular React children or a function that receives render props:
boolean
Changes the matching logic for the active and pending states to only match to the “end” of the to path.
<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.boolean
Changes the matching logic to make it case-sensitive:
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.