fix(router): fix nested deactivation
This commit is contained in:
parent
820eeb49d1
commit
1f3f8ef6c8
|
@ -1,10 +1,12 @@
|
|||
import {Attribute, ComponentFactory, ComponentRef, Directive, ReflectiveInjector, ResolvedReflectiveProvider, ViewContainerRef} from '@angular/core';
|
||||
import {RouterOutletMap} from '../router_outlet_map';
|
||||
import {ActivatedRoute} from '../router_state';
|
||||
import {PRIMARY_OUTLET} from '../shared';
|
||||
|
||||
@Directive({selector: 'router-outlet'})
|
||||
export class RouterOutlet {
|
||||
private activated: ComponentRef<any>|null;
|
||||
private _activatedRoute: ActivatedRoute|null;
|
||||
public outletMap: RouterOutletMap;
|
||||
|
||||
/**
|
||||
|
@ -21,6 +23,10 @@ export class RouterOutlet {
|
|||
if (!this.activated) throw new Error('Outlet is not activated');
|
||||
return this.activated.instance;
|
||||
}
|
||||
get activatedRoute(): ActivatedRoute {
|
||||
if (!this.activated) throw new Error('Outlet is not activated');
|
||||
return this._activatedRoute;
|
||||
}
|
||||
|
||||
deactivate(): void {
|
||||
if (this.activated) {
|
||||
|
@ -30,9 +36,10 @@ export class RouterOutlet {
|
|||
}
|
||||
|
||||
activate(
|
||||
factory: ComponentFactory<any>, providers: ResolvedReflectiveProvider[],
|
||||
factory: ComponentFactory<any>, activatedRoute: ActivatedRoute, providers: ResolvedReflectiveProvider[],
|
||||
outletMap: RouterOutletMap): void {
|
||||
this.outletMap = outletMap;
|
||||
this._activatedRoute = activatedRoute;
|
||||
const inj = ReflectiveInjector.fromResolvedProviders(providers, this.location.parentInjector);
|
||||
this.activated = this.location.createComponent(factory, this.location.length, inj, []);
|
||||
}
|
||||
|
|
|
@ -231,6 +231,7 @@ export class Router {
|
|||
|
||||
private runNavigate(url: UrlTree, pop: boolean, id: number): Promise<boolean> {
|
||||
if (id !== this.navigationId) {
|
||||
this.location.go(this.urlSerializer.serialize(this.currentUrlTree));
|
||||
this.routerEvents.next(new NavigationCancel(id, url));
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
@ -263,6 +264,7 @@ export class Router {
|
|||
})
|
||||
.forEach((shouldActivate) => {
|
||||
if (!shouldActivate || id !== this.navigationId) {
|
||||
this.location.go(this.urlSerializer.serialize(this.currentUrlTree));
|
||||
this.routerEvents.next(new NavigationCancel(id, url));
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
@ -355,7 +357,7 @@ class GuardChecks {
|
|||
if (outlet && outlet.isActivated) {
|
||||
forEach(
|
||||
outlet.outletMap._outlets,
|
||||
(v, k) => this.deactivateOutletAndItChildren(v, outlet.outletMap._outlets[k]));
|
||||
(v, k) => this.deactivateOutletAndItChildren(v.activatedRoute.snapshot, v));
|
||||
this.checks.push(new CanDeactivate(outlet.component, route));
|
||||
}
|
||||
}
|
||||
|
@ -447,7 +449,7 @@ class ActivateRoutes {
|
|||
{provide: ActivatedRoute, useValue: future},
|
||||
{provide: RouterOutletMap, useValue: outletMap}
|
||||
]);
|
||||
outlet.activate(future._futureSnapshot._resolvedComponentFactory, resolved, outletMap);
|
||||
outlet.activate(future._futureSnapshot._resolvedComponentFactory, future, resolved, outletMap);
|
||||
advanceActivatedRoute(future);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue