-
Notifications
You must be signed in to change notification settings - Fork 27.5k
feat($route): ability to cancel $routeChangeStart event #9502
Conversation
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
@caitp Hi Caitlin, @IgorMinar and I just came up with this implementation to prevent route change. Can you take a look? |
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 #5581 Closes #5714 Closes #9502
Not keen on the breaking change since this was perfectly implementable without it, but hey |
It wasn't without hacks that restored the location state.
|
cancelling $locationChangeStart should restore the location state, there is logic within $location itself to do that |
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
@@ -481,7 +533,7 @@ describe('$route', function() { | |||
|
|||
|
|||
describe('events', function() { | |||
it('should not fire $after/beforeRouteChange during bootstrap (if no route)', function() { | |||
it('should not fire $routeChangeStart/success during bootstrap (if no route)', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Success
? (capital S)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, thanks for catching this. Could you create a PR to fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling
preventDefault()
on a$routeChangeStart
event willprevent 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 #5581
Closes #5714