-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat(ngRoute): cancel $routeChangeStart via $event.preventDefault() #5714
Conversation
but this doesn't restore the $location.url() value, so now we have this weird state in which the url doesn't match the current route according to the route definition. I think that if we do allow route changes to be aborted then we should restore the $location state as well. This issue is one of the reasons why we currently allow $location changes to be aborted but don't offer this functionality at the $route layer. |
I think it's fixable though... :) |
I'm not totally sure how to go about asking the history api to go back/unpush state if it needs to within this framework, which seems like it might be a nice thing. |
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
@caitp, @yoerlemans good luck! I'm howling as well for a fix for that situation. |
why this is not already integrated? It would be nice to have it on 1.2.x releases. |
oh look at that, it's bitrotten! anyways, I think an alternative solution had been proposed, but I can't recall where (I think Vojta was looking at it). So this might not be the one that ships, but I'll see if we can ship one of the solutions for the next release |
02dc2aa
to
fd2d6c0
Compare
@IgorMinar I am interested in this functionality as a way to prevent reloading of the entire ng-view when a route changes from (e.g.) |
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
abdaab7
to
30996f8
Compare
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
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 #5581