history.replaceState still adds entries to the “Br

2020-05-23 01:06发布

问题:

Specifically, calling the following snippet of code:

history.replaceState(undefined, undefined, "#" + value)

will correctly not affect the back button behavior of the current page, but will add an entry to the "browsing history" page, which I don’t want. Pictured below is Chrome’s History page, but this also happens in Firefox.

Is there some way to replace the current URL without adding an entry to the user’s browsing history?

I’m inquiring about the standalone Browser History page, not the actual page navigation history that the Back button uses.

回答1:

I can't find any W3C spec on the global history, but even the session history is left unspecified to what the expected behavior is.

In practice, this has been an open bug for over 8 years with most of the browsers choosing to implement global history this way. In short, there probably isn't a workaround other than not calling pushState/replaceState.