Skip to content
Discussion options

You must be logged in to vote

Leaving this comment here in case others have the same question in the future:

I ended up going with

window.history.replaceState({ ...window.history.state, as: newUrl, url: newUrl }, '', newUrl);

for when I wanted to update the url without doing any re-rendering. I also check against Router.pathname and only use history.replaceState when remaining on the same page. Otherwise I use the nextjs Router.

Specifying window.history.state is mandatory because it maintains some nextjs state internals. If you pass {} instead of window.history.state, moving forward/back will potentially be broken. This was the hardest issue for me to fix.

Replies: 12 comments 43 replies

Comment options

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

@jamesmosier
Comment options

@matthewwolfe
Comment options

Comment options

You must be logged in to vote
31 replies
@mansigeek
Comment options

@JCs3lma
Comment options

@earthlingdavey
Comment options

@topolanekmartin
Comment options

@GrahamQuan
Comment options

Answer selected by matthewwolfe
Comment options

You must be logged in to vote
2 replies
@akash-mahmud
Comment options

@bamdadfr
Comment options

Comment options

You must be logged in to vote
2 replies
@HelaGone
Comment options

@kcrwfrd
Comment options

Comment options

You must be logged in to vote
1 reply
@earthlingdavey
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@antofa
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@ekebobrown
Comment options

Comment options

You must be logged in to vote
1 reply
@earthlingdavey
Comment options

Comment options

You must be logged in to vote
1 reply
@ptvty
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet