fix(router): fix redirectTo on named outlets - resolves #33783 (#47927)

fix(router): fix redirectTo on named outlets - resolves #33783

PR Close #47927
This commit is contained in:
Albert Szekely
2022-10-30 14:43:33 +02:00
committed by Andrew Kushnir
parent 6d4f75931b
commit db867fee77
3 changed files with 24 additions and 2 deletions
+2 -2
View File
@@ -84,8 +84,8 @@ function validateNode(route: Route, fullPath: string, requireStandaloneComponent
RuntimeErrorCode.INVALID_ROUTE_CONFIG,
`Invalid configuration of route '${fullPath}': Array cannot be specified`);
}
if (!route.component && !route.loadComponent && !route.children && !route.loadChildren &&
(route.outlet && route.outlet !== PRIMARY_OUTLET)) {
if (!route.redirectTo && !route.component && !route.loadComponent && !route.children &&
!route.loadChildren && (route.outlet && route.outlet !== PRIMARY_OUTLET)) {
throw new RuntimeError(
RuntimeErrorCode.INVALID_ROUTE_CONFIG,
`Invalid configuration of route '${
+6
View File
@@ -157,6 +157,12 @@ describe('config', () => {
validateConfig([{path: 'a', outlet: 'aux', loadChildren: jasmine.createSpy('child')}]);
}).not.toThrow();
});
it('should not throw when outlet has redirectTo', () => {
expect(() => {
validateConfig([{path: '', pathMatch: 'prefix', outlet: 'aux', redirectTo: 'main'}]);
}).not.toThrow();
});
});
});
+16
View File
@@ -3006,6 +3006,22 @@ describe('Integration', () => {
expect(history[history.length - 1].state)
.toEqual({foo: 'bar', navigationId: history.length});
})));
it('can redirect from componentless named outlets', fakeAsync(() => {
const router = TestBed.inject(Router);
const fixture = createRoot(router, RootCmp);
router.resetConfig([
{path: 'main', outlet: 'aux', component: BlankCmp},
{path: '', pathMatch: 'full', outlet: 'aux', redirectTo: 'main'},
]);
router.navigateByUrl('');
advance(fixture);
expect(TestBed.inject(Location).path()).toEqual('/(aux:main)');
}));
});
it('should set href on area elements', fakeAsync(() => {