Hello and thank you for your time!
I was learning by following a React course: https://app.pluralsight.com/library/courses/react-flux-building-applications/table-of-contents
And it looks like the React Router API has changed a lot since the course was filmed.
In the course it is taught how to use willTransitionFrom and willTransitionTo which both look like they are deprecated:https://github.com/ReactTraining/react-router/issues/1388
I would like to follow along, and I have tried to do the detect if the user is going to leave the current page. I have done:
window.addEventListener('beforeunload', (event) => {
if (!(window.confirm("DO YOU really want to exit a fun page like this?"))) {
event.preventDefault();
}
});
And also:
window.onbeforeunload = (event) => {
if (!(window.confirm("DO YOU really want to exit a fun page like this?"))) {
event.preventDefault();
}
};
It looks like neither of them gets fired, because I would like to show the confirm dialog when you try to load another page.
I have read: How to check if user is refreshing the page or navigating to other page How to display a pop up, when a user tries to leave the current page? https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload
Thank you for your help.