-
Notifications
You must be signed in to change notification settings - Fork 27.3k
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
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$routeChangeStartevent willprevent the route change and also call
preventDefaulton the$locationChangeStartevent, which prevents the location change as well.BREAKING CHANGE:
Order of events has changed.
Previously:
$locationChangeStart->$locationChangeSuccess->
$routeChangeStart->$routeChangeSuccessNow:
$locationChangeStart->$routeChangeStart->
$locationChangeSuccess-> ->$routeChangeSuccessFixes #5581
Closes #5714