title: Equivalence of window.onbeforeunload in AngularJS for routes
body: <p>Regular JavaScript has window.onbeforeunload. How do I emulate the same in AngularJS with HTML5 routes?</p>
  
  <p>There is $beforeRouteChange, but it doesn't allow you to cancel the event as far as I can tell.</p>
  
  <p>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.</p>