在window.popstate上获取新的URL

7 javascript popstate

有什么办法可以在window.popstate被解雇时获得新页面的网址吗?

window.onpopstate(function (){
    newPageUrl = //get the new page's URL
})
Run Code Online (Sandbox Code Playgroud)

KAN*_* UG 12

用这个

window.onpopstate(function (){
    newPageUrl = location.href;
})
Run Code Online (Sandbox Code Playgroud)

  • 基本上,当事件回调被击中时,路由更改已经注册。所以 currentUrl 已经是 newUrl (2认同)