From 40b92ddf21f655636b4cdc97dead97c6c92074a4 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Wed, 5 Oct 2016 15:37:32 -0700 Subject: [PATCH] fix(router): wildcards routes should support lazy loading Closes #12024 --- modules/@angular/router/src/apply_redirects.ts | 9 ++++++++- .../@angular/router/test/apply_redirects.spec.ts | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/@angular/router/src/apply_redirects.ts b/modules/@angular/router/src/apply_redirects.ts index 694c051394..3b3257b995 100644 --- a/modules/@angular/router/src/apply_redirects.ts +++ b/modules/@angular/router/src/apply_redirects.ts @@ -211,7 +211,14 @@ class ApplyRedirects { injector: Injector, rawSegmentGroup: UrlSegmentGroup, route: Route, segments: UrlSegment[]): Observable { if (route.path === '**') { - return of (new UrlSegmentGroup(segments, {})); + if (route.loadChildren) { + return map.call(this.configLoader.load(injector, route.loadChildren), (r: any) => { + (route)._loadedConfig = r; + return of (new UrlSegmentGroup(segments, {})); + }); + } else { + return of (new UrlSegmentGroup(segments, {})); + } } else { const {matched, consumedSegments, lastChild} = match(rawSegmentGroup, route, segments); diff --git a/modules/@angular/router/test/apply_redirects.spec.ts b/modules/@angular/router/test/apply_redirects.spec.ts index ceae5f3cc2..a6ab23c4a4 100644 --- a/modules/@angular/router/test/apply_redirects.spec.ts +++ b/modules/@angular/router/test/apply_redirects.spec.ts @@ -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}], 'stubInjector', 'stubFactoryResolver'); + + const loader = {load: (injector: any, p: any) => of (loadedConfig)}; + + const config = [{path: '**', loadChildren: 'children'}]; + + applyRedirects('providedInjector', loader, tree('xyz'), config).forEach(r => { + expect((config[0])._loadedConfig).toBe(loadedConfig); + }); + }); }); describe('empty paths', () => {