在首页页面加载事件中伪造一条历史记录即可
window.history.pushState(null, null, window.location.href);
补充:
监听前进、后退按钮
window.addEventListener("popstate", function () {
console.log(history.state);
})
切换到页面触发事件
window.addEventListener('pageshow', function(event) {
console.log('pageshow:');
console.log(event.persisted);
});
// event.persisted为true,表示从缓存读取,false表示从服务器返回。