Skip to content

Question About useParams Not Updating After window.history.pushState in Next.js 14.2.12 #70779

Answered by suprunchuk
JCs3lma asked this question in App Router
Discussion options

You must be logged in to vote

The issue you're encountering is due to how the useParams hook from next/navigation works in Next.js. The useParams hook is designed to work with Next.js's built-in routing system, which relies on the framework's internal mechanisms to detect route changes. When you use the window.history.pushState() method, you're bypassing these mechanisms, so useParams doesn't detect the change.

Here's how you can address this issue:

Solution: Use Next.js Routing
Instead of using window.history.pushState(), you should use Next.js's built-in routing capabilities, such as the useRouter hook from next/router. This will ensure that your component re-renders with the updated parameters when the URL changes.

H…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@JCs3lma
Comment options

@David05500
Comment options

@ajaxpost
Comment options

Answer selected by JCs3lma
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants