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
Uh oh!
There was an error while loading. Please reload this page.
-
For the directory structure below:
There seems to be two hooks to get the current URL:
useParamsreturns params in object format{user_id: '1', post_id: '2'}and works in the server-sideusePathnamereturns the current full URL/posts/1/2and 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.pushStateas advised here in the docs:So I have to get the full URL using
usePathnameand parse it manually to finduser_idandpost_id.Is this the correct way to achieve this?
useParamskeeps the original values from the initial request and does not update whenwindow.historyis 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 tousePathnameoruseSearchParamsas they get updated on client-side URL change.Beta Was this translation helpful? Give feedback.
All reactions