Equivalence of window.onbeforeunload in AngularJS for routes

Viewed 30282

Regular JavaScript has window.onbeforeunload. How do I emulate the same in AngularJS with HTML5 routes?

There is $beforeRouteChange, but it doesn't allow you to cancel the event as far as I can tell.

To clarify: window.onbeforeunload would work for navigating away from the page, but not for intra page navigation, e.g. going from one controller to another just through the HTML5 history API.

4 Answers
Related