Revert "fix(router): should throw when lazy loaded module doesn't define any routes (#15001)"
This reverts commit 82923a381d
.
This commit is contained in:
parent
fae47d86b3
commit
a7f2468184
|
@ -6,7 +6,7 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {Compiler, InjectionToken, Injector, NgModuleFactory, NgModuleFactoryLoader, NgModuleRef, ɵstringify as stringify} from '@angular/core';
|
import {Compiler, InjectionToken, Injector, NgModuleFactory, NgModuleFactoryLoader, NgModuleRef} from '@angular/core';
|
||||||
import {Observable} from 'rxjs/Observable';
|
import {Observable} from 'rxjs/Observable';
|
||||||
import {fromPromise} from 'rxjs/observable/fromPromise';
|
import {fromPromise} from 'rxjs/observable/fromPromise';
|
||||||
import {of } from 'rxjs/observable/of';
|
import {of } from 'rxjs/observable/of';
|
||||||
|
@ -41,16 +41,7 @@ export class RouterConfigLoader {
|
||||||
|
|
||||||
const module = factory.create(parentInjector);
|
const module = factory.create(parentInjector);
|
||||||
|
|
||||||
const parentRoutes = new Set(flatten(parentInjector.get(ROUTES)));
|
return new LoadedRouterConfig(flatten(module.injector.get(ROUTES)), module);
|
||||||
const moduleRoutes =
|
|
||||||
flatten(module.injector.get(ROUTES)).filter(route => !parentRoutes.has(route));
|
|
||||||
|
|
||||||
if (moduleRoutes.length === 0) {
|
|
||||||
throw new Error(
|
|
||||||
`A lazy loaded module must define at least 1 route, but it seems like the '${stringify(factory.moduleType)}' module hasn't defined any. Have you imported RouterModule.forChild(ROUTES) in this module?`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new LoadedRouterConfig(moduleRoutes, module);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2750,27 +2750,6 @@ describe('Integration', () => {
|
||||||
expect(fixture.nativeElement).toHaveText('lazy-loaded-parent [lazy-loaded-child]');
|
expect(fixture.nativeElement).toHaveText('lazy-loaded-parent [lazy-loaded-child]');
|
||||||
})));
|
})));
|
||||||
|
|
||||||
it(`should throw an error when lazy loaded module does not provide any routes`,
|
|
||||||
fakeAsync(inject(
|
|
||||||
[Router, Location, NgModuleFactoryLoader],
|
|
||||||
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
|
|
||||||
|
|
||||||
@NgModule({})
|
|
||||||
class LazyLoadedModule {
|
|
||||||
}
|
|
||||||
|
|
||||||
loader.stubbedModules = {expected: LazyLoadedModule};
|
|
||||||
|
|
||||||
const fixture = createRoot(router, RootCmp);
|
|
||||||
|
|
||||||
router.resetConfig([{path: 'lazy', loadChildren: 'expected'}]);
|
|
||||||
|
|
||||||
router.navigateByUrl('/lazy');
|
|
||||||
expect(() => advance(fixture))
|
|
||||||
.toThrowError(
|
|
||||||
/A lazy loaded module must define at least 1 route, but it seems like the 'LazyLoadedModule' module hasn't defined any/);
|
|
||||||
})));
|
|
||||||
|
|
||||||
it('should have 2 injector trees: module and element',
|
it('should have 2 injector trees: module and element',
|
||||||
fakeAsync(inject(
|
fakeAsync(inject(
|
||||||
[Router, Location, NgModuleFactoryLoader],
|
[Router, Location, NgModuleFactoryLoader],
|
||||||
|
|
Loading…
Reference in New Issue