Skip to content

Commit

Permalink
fix(router): fix redirectTo on named outlets - resolves #33783 (#47927)
Browse files Browse the repository at this point in the history
fix(router): fix redirectTo on named outlets - resolves #33783

PR Close #47927
  • Loading branch information
pixeldublu authored and AndrewKushnir committed Nov 4, 2022
1 parent 6d4f759 commit db867fe
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/router/src/utils/config.ts
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
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
Expand Up @@ -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(() => {
Expand Down

0 comments on commit db867fe

Please sign in to comment.