Active link highlighting? #911
Replies: 3 comments
-
This may not be the answer, but you can determine active link state using your own expression. const { location: { pathname } } = useRouterState()
const isActive = href.split('/')[1] === pathname.split('/')[1] // example matches '/foo' | '/foo/bar | '/foo/bar/1' |
Beta Was this translation helpful? Give feedback.
-
@blitzbohne |
Beta Was this translation helpful? Give feedback.
-
As @ashishsurya replied, the active class is applied. For those using Tailwind, you can use the className="[&.active]:text-green-500" Also, you might face an issue where all matched routes are highlighted. In this case, you should pass the activeOptions={{ exact: true }} prop. <Link
className="[&.active]:text-green-500 flex items-center gap-1"
activeOptions={{ exact: true }}
>
Your link
</Link> |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have a link with goes to the root "/" so I set activeProps={{exact:true}} to ensure it doesn't hit any other subroutes. However I also support subroutes on my root like "/dashboard" and of course the link doesn't highlight then. What's the proper solution to handle those special cases?
thanks
Alex
Beta Was this translation helpful? Give feedback.
All reactions