fix(router): wildcards routes should support lazy loading

Closes #12024
This commit is contained in:
vsavkin 2016-10-05 15:37:32 -07:00 committed by Tobias Bosch
parent 1681e4f57f
commit 40b92ddf21
2 changed files with 21 additions and 1 deletions

View File

@ -211,7 +211,14 @@ class ApplyRedirects {
injector: Injector, rawSegmentGroup: UrlSegmentGroup, route: Route,
segments: UrlSegment[]): Observable<UrlSegmentGroup> {
if (route.path === '**') {
if (route.loadChildren) {
return map.call(this.configLoader.load(injector, route.loadChildren), (r: any) => {
(<any>route)._loadedConfig = r;
return of (new UrlSegmentGroup(segments, {}));
});
} else {
return of (new UrlSegmentGroup(segments, {}));
}
} else {
const {matched, consumedSegments, lastChild} = match(rawSegmentGroup, route, segments);

View File

@ -292,6 +292,19 @@ describe('applyRedirects', () => {
},
(e) => { throw 'Should not reach'; });
});
it('should load the configuration of a whilecard route', () => {
const loadedConfig = new LoadedRouterConfig(
[{path: '', component: ComponentB}], <any>'stubInjector', <any>'stubFactoryResolver');
const loader = {load: (injector: any, p: any) => of (loadedConfig)};
const config = [{path: '**', loadChildren: 'children'}];
applyRedirects(<any>'providedInjector', <any>loader, tree('xyz'), config).forEach(r => {
expect((<any>config[0])._loadedConfig).toBe(loadedConfig);
});
});
});
describe('empty paths', () => {