fix(router): canDeactivate guards should run from bottom to top

Closes #15657.
This commit is contained in:
Roy Ling
2017-04-01 09:13:15 +08:00
committed by Alex Rickabaugh
parent eb6fb5f87e
commit e20cfe1bbc
2 changed files with 38 additions and 4 deletions

View File

@ -839,11 +839,10 @@ export class PreActivation {
// reusing the node
if (curr && future._routeConfig === curr._routeConfig) {
if (this.shouldRunGuardsAndResolvers(
curr, future, future._routeConfig !.runGuardsAndResolvers)) {
const shouldRunGuardsAndResolvers = this.shouldRunGuardsAndResolvers(
curr, future, future._routeConfig !.runGuardsAndResolvers);
if (shouldRunGuardsAndResolvers) {
this.canActivateChecks.push(new CanActivate(futurePath));
const outlet = context !.outlet !;
this.canDeactivateChecks.push(new CanDeactivate(outlet.component, curr));
} else {
// we need to set the data
future.data = curr.data;
@ -859,6 +858,11 @@ export class PreActivation {
} else {
this.traverseChildRoutes(futureNode, currNode, parentContexts, futurePath);
}
if (shouldRunGuardsAndResolvers) {
const outlet = context !.outlet !;
this.canDeactivateChecks.push(new CanDeactivate(outlet.component, curr));
}
} else {
if (curr) {
this.deactivateRouteAndItsChildren(currNode, context);