Skip to content

Commit db867fe

Browse files
pixeldubluAndrewKushnir
authored andcommitted
fix(router): fix redirectTo on named outlets - resolves #33783 (#47927)
fix(router): fix redirectTo on named outlets - resolves #33783 PR Close #47927
1 parent 6d4f759 commit db867fe

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

packages/router/src/utils/config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ function validateNode(route: Route, fullPath: string, requireStandaloneComponent
8484
RuntimeErrorCode.INVALID_ROUTE_CONFIG,
8585
`Invalid configuration of route '${fullPath}': Array cannot be specified`);
8686
}
87-
if (!route.component && !route.loadComponent && !route.children && !route.loadChildren &&
88-
(route.outlet && route.outlet !== PRIMARY_OUTLET)) {
87+
if (!route.redirectTo && !route.component && !route.loadComponent && !route.children &&
88+
!route.loadChildren && (route.outlet && route.outlet !== PRIMARY_OUTLET)) {
8989
throw new RuntimeError(
9090
RuntimeErrorCode.INVALID_ROUTE_CONFIG,
9191
`Invalid configuration of route '${

packages/router/test/config.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ describe('config', () => {
157157
validateConfig([{path: 'a', outlet: 'aux', loadChildren: jasmine.createSpy('child')}]);
158158
}).not.toThrow();
159159
});
160+
161+
it('should not throw when outlet has redirectTo', () => {
162+
expect(() => {
163+
validateConfig([{path: '', pathMatch: 'prefix', outlet: 'aux', redirectTo: 'main'}]);
164+
}).not.toThrow();
165+
});
160166
});
161167
});
162168

packages/router/test/integration.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,6 +3006,22 @@ describe('Integration', () => {
30063006
expect(history[history.length - 1].state)
30073007
.toEqual({foo: 'bar', navigationId: history.length});
30083008
})));
3009+
3010+
3011+
it('can redirect from componentless named outlets', fakeAsync(() => {
3012+
const router = TestBed.inject(Router);
3013+
const fixture = createRoot(router, RootCmp);
3014+
3015+
router.resetConfig([
3016+
{path: 'main', outlet: 'aux', component: BlankCmp},
3017+
{path: '', pathMatch: 'full', outlet: 'aux', redirectTo: 'main'},
3018+
]);
3019+
3020+
router.navigateByUrl('');
3021+
advance(fixture);
3022+
3023+
expect(TestBed.inject(Location).path()).toEqual('/(aux:main)');
3024+
}));
30093025
});
30103026

30113027
it('should set href on area elements', fakeAsync(() => {

0 commit comments

Comments
 (0)