How do I disable a browser back button click from user using react-router-dom
v4?
I am showing a modal on a page and when the user presses browser back button then the user is taken to the previous screen, instead I want to simply close the modal.
I tried doing this
onBackButtonEvent(event) {
event.preventDefault();
// the user shouldn't be able to move backward or forward
}
componentDidMount() {
window.onpopstate = this.onBackButtonEvent;
}
But this doesn't prevent the user from going backward or forward. Is there a way to handle this via react-router-dom
?
I have tried multiple solutions but nothing seems to work.