mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(router): fix redirectTo on named outlets - resolves #33783 PR Close #47927
This commit is contained in:
committed by
Andrew Kushnir
parent
6d4f75931b
commit
db867fee77
@@ -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 '${
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user