Next.js Discord

Discord Forum

Is it possible to get the route name client-side for the current route?

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
Let's say that I have a few routes:
- /route1/[id]
- /route1/[id]/route2
- /route1/[id]/route3
- /route4/[id]

Is there a way on the client side that I can get the route name (eg, /route1/[id]/route2). I know I can use usePathname to get the url path, but I am trying to create some client side defaulting in a hook based on the route name and using the path means that I then also have to create a bunch of regex's to match the url path. If I had the actual route name I could just create maps.

0 Replies