Handling route changes in AngularJS

angularjs, javascript

Solution

I believe $locationChangeStart fires when you would like it to.

Problem

I'm struggling to handle the back button and ask confirmation to the user, if app state is dirty. Closing tab and reload is already handled via the `onbeforeunload` hook. I've played with `$routeChangeStart`, `$beforeRouteChange`, etc. but can't handle it correctly. With `$routeChangeStart`, the route is effectively changed before my callback is called. What is the correct way to handle this situation? Thanks for your help.

Original source