Google Groups

Re: How to prevent hash/route change

Kai Groner Aug 3, 2012 9:21 PM
Posted in group: Angular and AngularJS discussion
The $location service broadcasts a $locationChangeStart event.  You can observe that and call event.preventDefault() to stop the navigation.  Nice!


On Thursday, July 26, 2012 2:29:45 AM UTC-4, Guiboy wrote:
I was looking at this problem too,  tried the above (old solution) without luck, i thought about making all my links check a service but that is too much work, it would be great to have a way to know that the route is about to change (a before route change event)  and a cancel route change method.

In my research i stumbled upon $routeChangeSuccess, but as the name suggest it is too late, you could make one stuck on one view buy redirecting back, but you lose all context as the controller will execute again, my current use for it is to redirect user to login screen in case he is not logged in

hope someone else chime in this issue

On Wednesday, July 18, 2012 9:57:39 AM UTC-3, Chadd Whistler wrote:
So this doesn't appear to work with the current 1.0.1 version.  Are there any other alternatives?
Just some more background, I am working on a financial application so I need to have complete control over navigation which includes changes directly to the URL in the address bar, the browser forward/back buttons and links from within my application.

On Tuesday, July 26, 2011 5:04:10 AM UTC-5, Adam Pohorecki wrote:

In my application I have several forms, and if a user enters some data
in a form and does not save it and then tries to navigate away from
the form (the current route changes), I would like to be able to show
a dialog saying like "You have unsaved data. Are you sure you want to
navigate away from this page?". Is it possible to somehow prevent a
route change with the current $route implementation?

Best regards,
Adam Pohorecki