[Router 3] CanDeactivate target route
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior When routing is about to happen, CanDeactivate guards can only know about component instance about to be deactivated/reused along with current route state of the application.
Expected/desired behavior
Add an extra parameter to CanDeactivate
interface - something like nextUrl
like so:
export interface CanDeactivate<T> {
canDeactivate(component: T, route: ActivatedRouteSnapshot, state: RouterStateSnapshot, nextUrl: string): Observable<boolean> | boolean;
}
Using nextUrl
instead of simple boolean value such as willReuse
could help further and mimic the same functionality as deprecated router.
What is the motivation / use case for changing the behavior?
This will help differentiate if the component will be deactivated or reused when the url changes. If the component is going to be destroyed, we can postpone the navigation as needed. This could be cleaning up some data (which will be unnecessary if the component is going to be reused and lifecycle hooks can be meaningless if this task runs on a service instead of component itself) or simply running some animations (which can be used page transitions; ngOnDestroy()
is run after component is detached and it does not wait for any observable like CanDeactivate
anyways).
Please tell us about your environment:
- Angular version: 2.0.0-rc.4 - @angular/router 3.0.0-beta.2
- Browser: [all ]
- Language: [ TypeScript ]
Issue Analytics
- State:
- Created 7 years ago
- Reactions:21
- Comments:21 (4 by maintainers)
+1 for this feature
According to the documentation https://angular.io/docs/ts/latest/guide/router.html
Right now it shows the current URL and not the future one so this should be a bug and not a feature request.
@vsavkin it seems that the other linked ticket https://github.com/angular/angular/issues/10186 with the bug report and the sample plunker is the correct one to keep open and fix isn’t it?