Revert "fix(router): pass correct component to canDeactivate checks when using two or more sibling router-outlets (#36302)" (#36697)
This reverts commit 80e6c07d89d74d71956fb1299c54f5353e255370. PR Close #36697
This commit is contained in:
parent
28ff02b116
commit
b5e92b9a5d
@ -83,7 +83,7 @@ function getChildRouteGuards(
|
|||||||
forEach(
|
forEach(
|
||||||
prevChildren,
|
prevChildren,
|
||||||
(v: TreeNode<ActivatedRouteSnapshot>, k: string) =>
|
(v: TreeNode<ActivatedRouteSnapshot>, k: string) =>
|
||||||
deactivateRouteAndItsChildren(v, contexts!.getContext(k), contexts, checks));
|
deactivateRouteAndItsChildren(v, contexts!.getContext(k), checks));
|
||||||
|
|
||||||
return checks;
|
return checks;
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ function getRouteGuards(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (curr) {
|
if (curr) {
|
||||||
deactivateRouteAndItsChildren(currNode, context, parentContexts, checks);
|
deactivateRouteAndItsChildren(currNode, context, checks);
|
||||||
}
|
}
|
||||||
|
|
||||||
checks.canActivateChecks.push(new CanActivate(futurePath));
|
checks.canActivateChecks.push(new CanActivate(futurePath));
|
||||||
@ -172,21 +172,17 @@ function shouldRunGuardsAndResolvers(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deactivateRouteAndItsChildren(
|
function deactivateRouteAndItsChildren(
|
||||||
route: TreeNode<ActivatedRouteSnapshot>, context: OutletContext|null,
|
route: TreeNode<ActivatedRouteSnapshot>, context: OutletContext|null, checks: Checks): void {
|
||||||
parentContexts: ChildrenOutletContexts|null, checks: Checks): void {
|
|
||||||
const children = nodeChildrenAsMap(route);
|
const children = nodeChildrenAsMap(route);
|
||||||
const r = route.value;
|
const r = route.value;
|
||||||
|
|
||||||
forEach(children, (node: TreeNode<ActivatedRouteSnapshot>, childName: string) => {
|
forEach(children, (node: TreeNode<ActivatedRouteSnapshot>, childName: string) => {
|
||||||
if (!r.component) {
|
if (!r.component) {
|
||||||
deactivateRouteAndItsChildren(
|
deactivateRouteAndItsChildren(node, context, checks);
|
||||||
node, parentContexts ? parentContexts.getContext(childName) : context, parentContexts,
|
|
||||||
checks);
|
|
||||||
} else if (context) {
|
} else if (context) {
|
||||||
deactivateRouteAndItsChildren(
|
deactivateRouteAndItsChildren(node, context.children.getContext(childName), checks);
|
||||||
node, context.children.getContext(childName), parentContexts, checks);
|
|
||||||
} else {
|
} else {
|
||||||
deactivateRouteAndItsChildren(node, null, parentContexts, checks);
|
deactivateRouteAndItsChildren(node, null, checks);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3046,44 +3046,6 @@ describe('Integration', () => {
|
|||||||
expect(location.path()).toEqual('/two-outlets/(a)');
|
expect(location.path()).toEqual('/two-outlets/(a)');
|
||||||
})));
|
})));
|
||||||
|
|
||||||
it('should call canDeactivate handler with each deactivated component',
|
|
||||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
|
||||||
const fixture = createRoot(router, TwoOutletsCmp);
|
|
||||||
|
|
||||||
router.resetConfig([
|
|
||||||
{
|
|
||||||
path: 'a',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
path: 'b1',
|
|
||||||
component: BlankCmp,
|
|
||||||
canDeactivate: ['RecordingDeactivate'],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'b2',
|
|
||||||
canDeactivate: ['RecordingDeactivate'],
|
|
||||||
component: SimpleCmp,
|
|
||||||
outlet: 'aux',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
path: 'c',
|
|
||||||
component: BlankCmp,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
router.navigate(['/a', {outlets: {primary: ['b1'], aux: ['b2']}}]);
|
|
||||||
advance(fixture);
|
|
||||||
expect(location.path()).toEqual('/a/(b1//aux:b2)');
|
|
||||||
|
|
||||||
router.navigate(['/c']);
|
|
||||||
advance(fixture);
|
|
||||||
|
|
||||||
expect(log[0].component).toBeAnInstanceOf(BlankCmp);
|
|
||||||
expect(log[1].component).toBeAnInstanceOf(SimpleCmp);
|
|
||||||
})));
|
|
||||||
|
|
||||||
it('works with a nested route',
|
it('works with a nested route',
|
||||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||||
const fixture = createRoot(router, RootCmp);
|
const fixture = createRoot(router, RootCmp);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user