如何使用react-router-dom
v4禁用用户单击浏览器后退按钮?
我在页面上显示一个模式,当用户按下浏览器后退按钮时,用户被带到上一个屏幕,而不是我想简单地关闭模式。
我试过这样做
onBackButtonEvent(event) {
event.preventDefault();
// the user shouldn't be able to move backward or forward
}
componentDidMount() {
window.onpopstate = this.onBackButtonEvent;
}
但这并不能阻止用户后退或前进。有没有办法通过 处理这个问题react-router-dom
?
我尝试了多种解决方案,但似乎没有任何效果。