fix(router): fix lazy loading of aux routes (#23459)

Fixes #10981

PR Close #23459
This commit is contained in:
Jason Aden
2018-04-06 15:56:36 -07:00
committed by Miško Hevery
parent 70ef061fa6
commit 5731d0741a
8 changed files with 131 additions and 17 deletions

View File

@ -3366,6 +3366,72 @@ describe('Integration', () => {
expect(location.path()).toEqual('/lazy2/loaded');
})));
it('should allow lazy loaded module in named outlet',
fakeAsync(inject(
[Router, NgModuleFactoryLoader], (router: Router, loader: SpyNgModuleFactoryLoader) => {
@Component({selector: 'lazy', template: 'lazy-loaded'})
class LazyComponent {
}
@NgModule({
declarations: [LazyComponent],
imports: [RouterModule.forChild([{path: '', component: LazyComponent}])]
})
class LazyLoadedModule {
}
loader.stubbedModules = {lazyModule: LazyLoadedModule};
const fixture = createRoot(router, RootCmp);
router.resetConfig([{
path: 'team/:id',
component: TeamCmp,
children: [
{path: 'user/:name', component: UserCmp},
{path: 'lazy', loadChildren: 'lazyModule', outlet: 'right'},
]
}]);
router.navigateByUrl('/team/22/user/john');
advance(fixture);
expect(fixture.nativeElement).toHaveText('team 22 [ user john, right: ]');
router.navigateByUrl('/team/22/(user/john//right:lazy)');
advance(fixture);
expect(fixture.nativeElement).toHaveText('team 22 [ user john, right: lazy-loaded ]');
})));
it('should allow componentless named outlet to render children',
fakeAsync(inject(
[Router, NgModuleFactoryLoader], (router: Router, loader: SpyNgModuleFactoryLoader) => {
const fixture = createRoot(router, RootCmp);
router.resetConfig([{
path: 'team/:id',
component: TeamCmp,
children: [
{path: 'user/:name', component: UserCmp},
{path: 'simple', outlet: 'right', children: [{path: '', component: SimpleCmp}]},
]
}]);
router.navigateByUrl('/team/22/user/john');
advance(fixture);
expect(fixture.nativeElement).toHaveText('team 22 [ user john, right: ]');
router.navigateByUrl('/team/22/(user/john//right:simple)');
advance(fixture);
expect(fixture.nativeElement).toHaveText('team 22 [ user john, right: simple ]');
})));
describe('should use the injector of the lazily-loaded configuration', () => {
class LazyLoadedServiceDefinedInModule {}
@ -4102,6 +4168,10 @@ function createRoot(router: Router, type: any): ComponentFixture<any> {
return f;
}
@Component({selector: 'lazy', template: 'lazy-loaded'})
class LazyComponent {
}
@NgModule({
imports: [RouterTestingModule, CommonModule],