I have tried to occur an aler <Modal />
only when browser back. But currently, default alert shows and everytime when I leave from this website an alert occurs. How can I fix this?
constructor(props) {
super(props);
this.onUnload = this.onUnload.bind(this);
}
onUnload(event) {
console.log("alert");
event.returnValue = "alert";
}
componentDidMount() {
window.addEventListener("beforeunload", this.onUnload);
}
componentWillUnmount() {
window.removeEventListener("beforeunload", this.onUnload);
}