0
當推到歷史和不改變URL設置數據:爲什麼與同一location.href(或空)按下時window.onpopstate空event.state
window.history.pushState({
stateName: "myStateName",
randomData: window.Math.random()
}, "myStateName", location.href);
....然後聽
window.onpopstate = function(event) {
console.log(event.state); //logs null
}
您將大部分的時間得到null作爲狀態值,而不是:
{
stateName: "myStateName",
randomData: 0.34234234234
}
流行事件,並通過在瀏覽器中按後退按鈕觸發它
我該如何解決這個問題,爲什麼會發生這種情況?