From 0eca960494b55c4f1c02d6d24ee397b758831eea Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Wed, 28 Dec 2016 02:22:57 +0300 Subject: [PATCH] fix(router): fix lazy loaded module with wildcard route (#13649) Closes #12955 --- .../@angular/router/src/apply_redirects.ts | 4 +-- .../@angular/router/test/integration.spec.ts | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/modules/@angular/router/src/apply_redirects.ts b/modules/@angular/router/src/apply_redirects.ts index d4dabdb987..2b0aa4c452 100644 --- a/modules/@angular/router/src/apply_redirects.ts +++ b/modules/@angular/router/src/apply_redirects.ts @@ -235,7 +235,7 @@ class ApplyRedirects { if (route.loadChildren) { return map.call(this.configLoader.load(injector, route.loadChildren), (r: any) => { (route)._loadedConfig = r; - return of (new UrlSegmentGroup(segments, {})); + return new UrlSegmentGroup(segments, {}); }); } else { return of (new UrlSegmentGroup(segments, {})); @@ -503,4 +503,4 @@ function emptyPathRedirect( function getOutlet(route: Route): string { return route.outlet ? route.outlet : PRIMARY_OUTLET; -} \ No newline at end of file +} diff --git a/modules/@angular/router/test/integration.spec.ts b/modules/@angular/router/test/integration.spec.ts index b09d342a70..a0480b8827 100644 --- a/modules/@angular/router/test/integration.spec.ts +++ b/modules/@angular/router/test/integration.spec.ts @@ -2378,6 +2378,32 @@ describe('Integration', () => { expect(location.path()).toEqual('/lazy/loaded'); }))); + it('should work with wildcard route', + fakeAsync(inject( + [Router, Location, NgModuleFactoryLoader], + (router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => { + @Component({selector: 'lazy', template: 'lazy-loaded'}) + class LazyLoadedComponent { + } + + @NgModule({ + declarations: [LazyLoadedComponent], + imports: [RouterModule.forChild([{path: '', component: LazyLoadedComponent}])], + }) + class LoadedModule { + } + + loader.stubbedModules = {lazy: LoadedModule}; + const fixture = createRoot(router, RootCmp); + + router.resetConfig([{path: '**', loadChildren: 'lazy'}]); + + router.navigateByUrl('/lazy'); + advance(fixture); + + expect(location.path()).toEqual('/lazy'); + }))); + describe('preloading', () => { beforeEach(() => { TestBed.configureTestingModule(