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?

9 Replies
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β’3y ago
There's activeprops for link components
deep-jadeOPβ’3y ago
Do you know if there is a way to grab that info from a hook??
deep-jadeβ’3y ago
I haven't found it, but I definitely want it!!
deep-jadeOPβ’3y ago
FYI, this can be found on
useRouter().statedeep-jadeβ’3y ago
Thank you for updating Nick
rival-blackβ’3y ago
this helped a lot! thank you
correct-apricotβ’2y ago
Thanks @Nick Young
noble-goldβ’2y ago
The useRouterState hook is also a way of achieving this.