我需要保存在本地存儲的URL,只要組件正在卸載:組件將卸載沒有得到後錨標記點擊堪稱反應
componentWillUnmount(){
console.log("componentWillUnmount will call here.");
console.log("window.redirect.url",window.location.pathname);
localStorage.setItem("prevUrl",window.location.pathname);
}
在另一種情況下,如果存在這樣的情況,當錨標記被點擊,上述方法不叫:
<a href="/differentpage">differentpage </a>
我無法執行unmount方法。有什麼辦法可以執行卸載嗎?
是'differentpage'是在你的SPA路線(反應路由器)或不同的頁面都在一起? –