Skip to content

Commit b2dffb9

Browse files
committed
fix(router): fix redirectTo on named outlets - resolves #33783
fix(router): fix redirectTo on named outlets - resolves #33783
1 parent 37ba610 commit b2dffb9

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
@@ -2983,6 +2983,22 @@ describe('Integration', () => {
29832983
expect(history[history.length - 1].state)
29842984
.toEqual({foo: 'bar', navigationId: history.length});
29852985
})));
2986+
2987+
2988+
it('can redirect from componentless named outlets', fakeAsync(() => {
2989+
const router = TestBed.inject(Router);
2990+
const fixture = createRoot(router, RootCmp);
2991+
2992+
router.resetConfig([
2993+
{path: 'main', outlet: 'aux', component: BlankCmp},
2994+
{path: '', pathMatch: 'full', outlet: 'aux', redirectTo: 'main'},
2995+
]);
2996+
2997+
router.navigateByUrl('');
2998+
advance(fixture);
2999+
3000+
expect(TestBed.inject(Location).path()).toEqual('/(aux:main)');
3001+
}));
29863002
});
29873003

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

0 commit comments

Comments
 (0)