-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Open
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: routerfreq1: lowrouter: guards/resolversstate: confirmedtype: bug/fix
Milestone
Description
π bug report
Affected Package
The issue is caused by package @angular/routerDescription
For some reason CanDeactivate guard gets called with an incorrect component instance.
In this case it should get called with a component that is mounted in a named outlet, but gets called with one from primary outlet. See example in stackblitz.
I'd expect that with configuration like below:
The guard should only be called when AdminHeaderComponent is being deactivated and only with this component instance.
One notable thing is that the currentRoute param is correct!
EDIT: found a workaround:
canDeactivate(component: HasComponentPendingChanges, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot) {
if (currentRoute.outlet === OVERLAY_OUTLET && this.router['rootContexts'] && this.router['rootContexts'].getContext) {
const context: OutletContext = this.router['rootContexts'].getContext(OVERLAY_OUTLET);
if (context && context.outlet && context.outlet.isActivated && context.outlet['activated'].instance) {
component = context.outlet['activated'].instance;
}
}
π¬ Minimal Reproduction
https://stackblitz.com/edit/angular-named-outlet-yfgsip?file=app%2Fadmin%2Fadmin.module.ts
- Open the link
- Open the console
- Click on
adminlink - Click on
create userlink - Observe that following message is printed:
deactivating UsersListComponent {}
deactivating CreateUserComponent {}
deactivating AdminHeaderComponent {}
^ all good
- Now the fun begins, click on
adminandcreate userlinks again - Click on
Component 2 - Observe that following messages are printed:
deactivating UsersListComponent {}
deactivating CreateUserComponent {}
deactivating CreateUserComponent {}
I'd argue that the last message should state AdminHeaderComponent
π Your Environment
Angular Version:
8.2.14
baconcutter, Airblader, reinvanleirsberghe, ivankardash, sylvaindumont and 2 more
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: routerfreq1: lowrouter: guards/resolversstate: confirmedtype: bug/fix