history.state is getting clobbered by Router
See original GitHub issueBug report
Describe the bug
Entries added to history.state are not preserved after navigating away and back to the page.
To Reproduce
- On any page, enter
history.replaceState({ ...history.state, hello: 'world' }, location.href)in the console - Click on a link that navigates away from the page
- Click “back” in the browser
- See that
console.log(history.state)does not include{hello: 'world'}
Expected behavior
{hello: 'world'} to be a part of the state.
System information
- OS: Ubuntu 18.04
- Browser: Chrome, Firefox
- Version of Next.js: 8.1.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Router: Deprecate or remove `navigationId` in `history.state ...
If the developer were to set a navigationId property it would get clobbered by Angular's setting of the same field.
Read more >Angular: history.state.data returns undefined instead of the last ...
Upon some research, I found that state doesnt work on non-anchor elements. To solve the issue, On routing programatically we can use state:....
Read more >History.pushState() - Web APIs | MDN
The state object is a JavaScript object which is associated with the new history entry created by pushState() . Whenever the user navigates ......
Read more >Backbone.js
History serves as a global router (per frame) to handle hashchange events or pushState, match the appropriate route, and trigger callbacks.
Read more >Rout Definition & Meaning - Merriam-Webster
a state of wild confusion or disorderly retreat. 2. a. : a disastrous defeat : debacle. b. : a precipitate flight. rout. 2...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

In this case I would recommend using query values in
hrefwhich you can hide usingas. This allows you to maintain state without having to interfere withhistory.state.This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.