question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

history.state is getting clobbered by Router

See original GitHub issue

Bug report

Describe the bug

Entries added to history.state are not preserved after navigating away and back to the page.

To Reproduce

  1. On any page, enter history.replaceState({ ...history.state, hello: 'world' }, location.href) in the console
  2. Click on a link that navigates away from the page
  3. Click “back” in the browser
  4. 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:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ijjkcommented, Jun 28, 2019

In this case I would recommend using query values in href which you can hide using as. This allows you to maintain state without having to interfere with history.state.

0reactions
balazsorban44commented, Jan 31, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found