尝试过下面的代码,但它没有破坏Popstate Event。
请帮助我们举例说明我可以Popstate Event根据条件销毁。
history.pushState(null, document.title, location.href);
window.addEventListener('popstate', function (event) {
if (true){
history.pushState(null, document.title, location.href);
console.log('Back Button Prevented');
} else {
window.removeEventListener('popstate', ()=> {
console.log('Go back');
}, true);
history.back();
}
});
Run Code Online (Sandbox Code Playgroud)