【发布时间】:2019-11-02 01:20:06
【问题描述】:
我有一个onpopstate 事件的侦听器。我想获得没有在历史中旅行而弹出的历史记录。我可以做history.forward() 并获取状态,但这会导致我不想看到的副作用。
window.addEventListener('popstate', (event) => {
prevHistoryRecord = // How to get it without history.forward()
});
【问题讨论】:
-
为什么不简单地使用 event.state 或 history.state?
-
因为事件状态和历史状态存储的是当前状态,而不是被弹出的状态