T
TanStackβ€’3y ago
deep-jade

Equivalent of useLocation?

Is there an equivalent to useLocation in react-router? I have a parent route with my nav bar and I want to highlight the current tab if the route matches. Do I need to use a dynamic route and get the segment with useParams? Or is there a way to get the pathname from the parent route and check if it matches one of the children?
No description
9 Replies
deep-jade
deep-jadeOPβ€’3y ago
This seems to do the trick, but doesn't "feel" like the right way to accomplish this. As I miss out on TS stuff. πŸ˜Άβ€πŸŒ«οΈ
deep-jade
deep-jadeβ€’3y ago
There's activeprops for link components
deep-jade
deep-jadeOPβ€’3y ago
Do you know if there is a way to grab that info from a hook??
deep-jade
deep-jadeβ€’3y ago
I haven't found it, but I definitely want it!!
deep-jade
deep-jadeOPβ€’3y ago
FYI, this can be found on useRouter().state
deep-jade
deep-jadeβ€’3y ago
Thank you for updating Nick
rival-black
rival-blackβ€’3y ago
this helped a lot! thank you
correct-apricot
correct-apricotβ€’2y ago
Thanks @Nick Young
noble-gold
noble-goldβ€’2y ago
The useRouterState hook is also a way of achieving this.
const location = useRouterState({ select: (s) => s.location });
const location = useRouterState({ select: (s) => s.location });

Did you find this page helpful?