usePathname() with dynamic segments
Unanswered
Common Yellowthroat posted this in #help-forum
Common YellowthroatOP
Hi all!
I'm trying to use the usePathname() hook to highlight the currently active link in a sidebar with App Router and dynamic segments. With the Pages Router this was easily possible because it returned the "raw" path for dynamic segments: /projects/[projectSlug] and this could be easily matched but now with the usePathname() hook I only get the fully rendered path: /projects/my-first-project which is essentially exactly the same as location.pathname would return and is pretty useless for path matching without using Regex.
Is there any other way to get the current path as-is in the directory structure?
I'm trying to use the usePathname() hook to highlight the currently active link in a sidebar with App Router and dynamic segments. With the Pages Router this was easily possible because it returned the "raw" path for dynamic segments: /projects/[projectSlug] and this could be easily matched but now with the usePathname() hook I only get the fully rendered path: /projects/my-first-project which is essentially exactly the same as location.pathname would return and is pretty useless for path matching without using Regex.
Is there any other way to get the current path as-is in the directory structure?
1 Reply
Sun bear
did you ever figure this out? trying to solve the same thing right now..