-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Ability to cancel $routeChangeStart event #5581
Comments
This is not ideal, but you could just listen on
|
You suggest something like this:
I thought there may be some functionality on the routeProvider to get the route data based on a url. Something like:
Thanks for your answer, btw. |
I have just given this a try... It did not work. $locationChangeStart fires before $routeChangeStart. Maybe that changes something in the order? |
👍 For the proposed fix. Too bad I can't use it right away 😄 |
This change allows ngRoute route changes to be cancelled using $event.preventDefault. This enables route changes to be aborted at the discretion of the application. Route changes may not be cancelled if forceReload is set to true. Closes angular#5581
I was bored and decided to push a clean patch for this @yoerlemans --- but if you reopen a PR I'll take a look at it and close mine. |
This change allows ngRoute route changes to be cancelled using $event.preventDefault. This enables route changes to be aborted at the discretion of the application. Route changes may not be cancelled if forceReload is set to true. Closes angular#5581
This change allows ngRoute route changes to be cancelled using $event.preventDefault. This enables route changes to be aborted at the discretion of the application. Route changes may not be cancelled if forceReload is set to true. Closes angular#5581
This change allows ngRoute route changes to be cancelled using $event.preventDefault. This enables route changes to be aborted at the discretion of the application. Route changes may not be cancelled if forceReload is set to true. Closes angular#5581
This change allows ngRoute route changes to be cancelled using $event.preventDefault. This enables route changes to be aborted at the discretion of the application. Route changes may not be cancelled if forceReload is set to true. Closes angular#5581
@IgorMinar, @yoerlemans so... any other alternative for this? How can I stop the change after the next route has been parsed? As the parseRoute API is not exposed, is my only alternative to copy that code into my app and parse the paths in |
+1 |
For anyone who wants to reject a route change (e.g. for authentication/authorization purposes), as a workaround for this issue, check out this plnkr. |
+1 👍 |
+1 for the proposed fix. |
+1 clean and nice solution |
+1 👍 |
#4192 will solve this. |
+1 helped me too |
Thanks for the workaround. Are there any plans for when the fix for this issue will be available in one of the stable builds? |
@khellang's solution works for me. Thanks. |
Building on the example provided by @khellang , here is an demo of how you can pass rights/roles to the route provider. |
Previously, one could perform this feat by listening to both $locationChangeStart as well as $routeChangeStart, and being careful to update the route correctly. Now, it's possible to simply preventDefault() on the $beforeRouteChange event in order to prevent location and route from being updated. While this does not cancel $routeChangeStart, it does ensure that the correct location is restored, and provides the same information as $routeChangeStart. Closes angular#5855 Closes angular#5714 Closes angular#5581
Previously, one could perform this feat by listening to both $locationChangeStart as well as $routeChangeStart, and being careful to update the route correctly. Now, it's possible to simply preventDefault() on the $beforeRouteChange event in order to prevent location and route from being updated. While this does not cancel $routeChangeStart, it does ensure that the correct location is restored, and provides the same information as $routeChangeStart. Closes angular#5855 Closes angular#5714 Closes angular#5581
Calling `preventDefault()` on a `$routeChangeStart` event will prevent the route change and also call `preventDefault` on the `$locationChangeStart` event, which prevents the location change as well. BREAKING CHANGE: Order of events has changed. Previously: `$locationChangeStart` -> `$locationChangeSuccess` -> `$routeChangeStart` -> `$routeChangeSuccess` Now: `$locationChangeStart` -> `$routeChangeStart` -> `$locationChangeSuccess` -> -> `$routeChangeSuccess` Fixes angular#5581 Closes angular#5714
Calling `preventDefault()` on a `$routeChangeStart` event will prevent the route change and also call `preventDefault` on the `$locationChangeStart` event, which prevents the location change as well. BREAKING CHANGE: Order of events has changed. Previously: `$locationChangeStart` -> `$locationChangeSuccess` -> `$routeChangeStart` -> `$routeChangeSuccess` Now: `$locationChangeStart` -> `$routeChangeStart` -> `$locationChangeSuccess` -> -> `$routeChangeSuccess` Fixes angular#5581 Closes angular#5714 Closes angular#9502
Hi, I have an issue which seems to occur more often in the community.
It's the same as #592 and multiple stackoverflow posts (http://stackoverflow.com/questions/14895016 - http://stackoverflow.com/questions/16344223 etc)
Some of these issues were resolved by using locationChangeStart.
It would work too for me, if not for the next problem.
I'm making an app with some standard pages like a home-page and a contact-page. Then we have some kind of wizard. The routes look like this.
Now I can complete the wizard and save on the WizardSavePage. But what I want is when I'm on WizardPage2 and I navigate to home or contact, I want to show a confirmation "You have unsaved changes. Do you want to continue" or something.
The easiest code would be:
But this does not work, obviously. I could do this with locationChangeStart but then I lose all the route data.
What would be the best way to make something like this?
Thanks in advance!
The text was updated successfully, but these errors were encountered: