I am using the HTML5 history API
I notice that if:
- if I am on a page called /first
- I use pushState to /second
- And then hit the back button
The event handler for window.onpopstate() returns the state for /first, as documented.
In order to transition from /second to /first, I would like to see the URL that was popped – ie, /second in this case. What’s the best way of doing that?
In lieu of a proper answer, I’ve implemented the following workaround:
data-urlhackattribute on the<body>element when a page is loadedonpopstate()handler, checking the value of this attribute so I can transition from this page (where the back button was hit) to the page the back button has sent us to.Also ensure that pages loaded in
onpopstate()don’t try and push usepushState()themselves.