Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/router/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 '${
Expand Down
6 changes: 6 additions & 0 deletions packages/router/test/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});

Expand Down
16 changes: 16 additions & 0 deletions packages/router/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2983,6 +2983,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(() => {
Expand Down