0
  const confirmExit = (e) => {
      let dialogText = 'You have unsaved changes. If you leave this page all changes will be lost. Do you wish to continue?';
      e.returnValue = dialogText;
      return dialogText;
    }

    window.onbeforeunload = confirmExit;

How to add a condition once the user confirmed the reload option so that i can route to the root page of the app?

before: http://localhost:9000/test

After the user confirmed the refresh button: http://localhost:9000/

user3278612
  • 201
  • 2
  • 11

1 Answers1

0

try using window.location.href="your-redirected-url-here";
However- if you do not want the user to go back to the earlier page, then try this:
window.location.replac="your-redirected-url-here";
this will remove the earlier page from the history.

Araphel
  • 309
  • 1
  • 10