Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(router): fix lazy loaded module with wildcard route #13649

Merged
merged 1 commit into from
Dec 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/@angular/router/src/apply_redirects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class ApplyRedirects {
if (route.loadChildren) {
return map.call(this.configLoader.load(injector, route.loadChildren), (r: any) => {
(<any>route)._loadedConfig = r;
return of (new UrlSegmentGroup(segments, {}));
return new UrlSegmentGroup(segments, {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then the return type is wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? We are inside map:

return map.call(...)

Before the fix the actual return type was Observable<Observable<UrlSegmentGroup>> (don't know why ts doesn't do type checking here, but it's a fact) and now it's Observable<UrlSegmentGroup>.

Another solution would be to replace map with mergeMap to flatten the inner observable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are inside map

You're right, I missed that.

});
} else {
return of (new UrlSegmentGroup(segments, {}));
Expand Down Expand Up @@ -503,4 +503,4 @@ function emptyPathRedirect(

function getOutlet(route: Route): string {
return route.outlet ? route.outlet : PRIMARY_OUTLET;
}
}
26 changes: 26 additions & 0 deletions modules/@angular/router/test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2295,6 +2295,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(
Expand Down