Add URL params to usePathname #73656
Unanswered
ptvty
asked this question in
App Router
Replies: 1 comment 2 replies
-
@icyJoseph Here's a PoC The |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For the directory structure below:
There seems to be two hooks to get the current URL:
useParams
returns params in object format{user_id: '1', post_id: '2'}
and works in the server-sideusePathname
returns the current full URL/posts/1/2
and works only in the client-sideI need to get the URL params in the client side and get those in clean object format.
My use case is to have client-side navigation for switching tabs. I'm using
window.history.pushState
as advised here in the docs:So I have to get the full URL using
usePathname
and parse it manually to finduser_id
andpost_id
.Is this the correct way to achieve this?
useParams
keeps the original values from the initial request and does not update whenwindow.history
is used for a navigation. I would be happy if it retained its functionality in the client-side or I could have the same object format added tousePathname
oruseSearchParams
as they get updated on client-side URL change.Beta Was this translation helpful? Give feedback.
All reactions