I have a little website using different routes and components (made with React and React Router). I am trying to prevent the user from refreshing in a specific form page, the problem: The Listener prevents the user from refreshing anywhere. But I want that listener only to trigger on that specific page. So how can I do that?
window.addEventListener('beforeunload', function (e) {
return "data will get lost"
});
^ This is the snippet I used in one component, that is not displayed permanently, but only on a specific route.