JS Redirect Prevents Going Back to Previous Page, No History Record

window.location.replace

1 
window.location.replace('page to redirect to') // No history record 
1 2 3 4 
let backLen = history.length history.forward() history.go(-backLen) // Return at the beginning window.location.replace('/#/home') 

window.location.hash

JS clears history by changing location.hash

Use the following method to assign a value to hash

1 
window.location.hash = 'hash value' 

This will add a new history entry in window.history. If you want to clear this record (otherwise clicking back will return to the previous hash page), you can use:

1 
window.location.replace(window.location.href.toString().replace(window.location.hash, '') + "#

评论

暂无评论。

登录后可发表评论。