The following code should cause an alert of \'1\', but instead does nothing.
window.onpopstate = function(event) { alert(event.state.a) }
history.pushState({
You have to modify the current state before push a new state. So, when you go back for the first state, you will get the data back:
// updating the current state
window.history.replaceState({a: 1}, "First State", window.location.pathname);
// setting the new state
window.history.pushState({ },"Secound State", window.location.pathname);
// getting the data back
window.onpopstate = (event) => {
alert(event.state.a); // Displays "1";
}