fix(router): pass correct component to canDeactivate checks when using two or more sibling router-outlets (#36302)
fixes #34614 There's an edge case where if I use two (or more) sibling <router-outlet>s in two (or more) child routes where their parent route doesn't have a component then preactivation will trigger all canDeactivate checks with the same component because it will use wrong OutletContext. PR Close #36302
This commit is contained in:
@ -3046,6 +3046,44 @@ describe('Integration', () => {
|
||||
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',
|
||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||
const fixture = createRoot(router, RootCmp);
|
||||
|
Reference in New Issue
Block a user