refactor(router): polishing
This commit is contained in:
parent
ea848f74af
commit
fb1be83a1b
|
@ -293,7 +293,7 @@ class ApplyRedirects {
|
|||
}
|
||||
|
||||
if (route.loadChildren) {
|
||||
return mergeMap.call(runGuards(ngModule.injector, route), (shouldLoad: any) => {
|
||||
return mergeMap.call(runCanLoadGuard(ngModule.injector, route), (shouldLoad: boolean) => {
|
||||
|
||||
if (shouldLoad) {
|
||||
return (<any>route)._loadedConfig ?
|
||||
|
@ -396,12 +396,12 @@ class ApplyRedirects {
|
|||
}
|
||||
}
|
||||
|
||||
function runGuards(moduleInjector: Injector, route: Route): Observable<boolean> {
|
||||
function runCanLoadGuard(moduleInjector: Injector, route: Route): Observable<boolean> {
|
||||
const canLoad = route.canLoad;
|
||||
if (!canLoad || canLoad.length === 0) return of (true);
|
||||
|
||||
const obs = map.call(from(canLoad), (c: any) => {
|
||||
const guard = moduleInjector.get(c);
|
||||
const obs = map.call(from(canLoad), (injectionToken: any) => {
|
||||
const guard = moduleInjector.get(injectionToken);
|
||||
return wrapIntoObservable(guard.canLoad ? guard.canLoad(route) : guard(route));
|
||||
});
|
||||
|
||||
|
|
|
@ -2075,7 +2075,6 @@ describe('Integration', () => {
|
|||
});
|
||||
|
||||
describe('CanLoad', () => {
|
||||
describe('should not load children when CanLoad returns false', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
|
@ -2093,7 +2092,7 @@ describe('Integration', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('works',
|
||||
it('should not load children when CanLoad returns false',
|
||||
fakeAsync(inject(
|
||||
[Router, Location, NgModuleFactoryLoader],
|
||||
(router: Router, location: Location, loader: SpyNgModuleFactoryLoader) => {
|
||||
|
@ -2171,12 +2170,10 @@ describe('Integration', () => {
|
|||
|
||||
expectEvents(recordedEvents, [
|
||||
[NavigationStart, '/lazyFalse/loaded'], [NavigationCancel, '/lazyFalse/loaded'],
|
||||
[NavigationStart, '/blank'], [RoutesRecognized, '/blank'],
|
||||
[NavigationEnd, '/blank']
|
||||
[NavigationStart, '/blank'], [RoutesRecognized, '/blank'], [NavigationEnd, '/blank']
|
||||
]);
|
||||
})));
|
||||
});
|
||||
});
|
||||
|
||||
describe('order', () => {
|
||||
|
||||
|
|
Loading…
Reference in New Issue