AngularJS confirm before route change

Viewed 30049

Is it possible to listen for route changes AND onwindowunload both to confirm page leave without saving changes?

Use cases:

  • User clicks Back
  • User presses back button in browser
  • User types in a different URL

If the user clicks 'cancel' stop the page / route change.

I've seen a few different examples but none worked quite right.

6 Answers
Related