When pushing to history and setting data without changing URL:
window.history.pushState({
stateName: "myStateName",
randomData: window.Math.random()
}, "myStateName", location.href);
.... and then listen to the pop event and trigger it by pressing the Back button in the browser:
window.onpopstate = function(event) {
console.log(event.state); //logs null
}
You will most of the time get null as the state value instead of:
{
stateName: "myStateName",
randomData: 0.34234234234
}
How can I solve this and why does this happen?