How to get router.pathname
value using usePathname()
?
#53461
Replies: 4 comments 5 replies
-
try useParams() instead of usePathname(). |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
import { useParams, usePathname } from "next/navigation"; // 获取page router下的router.pathname function useGetRawPath() { if (typeof params === "object" && params !== null) {
} else { |
Beta Was this translation helpful? Give feedback.
-
Hope it's okay to share this here — apologies in advance if this feels like self-promotion! I recently built a small package to address a similar issue. Hope it’s helpful! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Previously we had access to actual route name, that could be used in conditions, like this:
The problem now is, when we use the new usePathname hook, it returns the actual URL with param id and not the route name:
How do we get
/items/[id]/edit
route name?Beta Was this translation helpful? Give feedback.
All reactions