I want to have the confirmation dialog box from the browser only when browser/tab is closing or refresh is clicked.
Currently I use the following code but it beforeunload
is triggered even when the it's redirected to another page. I have a form and once the form data is submitted, the url is changed. I don't need the confirmation dialog box (with the text "Changes you made may not be saved.") to be visible everytime users click submit the form.
useBeforeunload(() => {
return "Are you sure you want to leave?";
});