Last active
March 20, 2019 21:25
-
-
Save arturovt/d4d6f2682c0e752ea70d104bb19a9f1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplyRedirects { | |
private getChildConfig( | |
ngModule: NgModuleRef<any>, | |
route: Route, | |
segments: UrlSegment[] | |
): Observable<LoadedRouterConfig> { | |
if (route.children) { | |
return of(new LoadedRouterConfig(route.children, ngModule)); | |
} | |
if (route.loadChildren) { | |
// Если мы уже загрузили модуль - берем из кеша | |
if (route._loadedConfig !== undefined) { | |
return of(route._loadedConfig); | |
} | |
// Существует также пермишн на загрузку ленивого модуля - `canLoad` | |
return runCanLoadGuard(ngModule.injector, route, segments).pipe( | |
mergeMap((shouldLoad: boolean) => { | |
if (shouldLoad) { | |
// `RouteConfigLoader.load` внутри метода вызывает | |
// `SystemJsNgModuleLoader.load` | |
return this.configLoader.load(ngModule.injector, route).pipe( | |
map((cfg: LoadedRouterConfig) => { | |
route._loadedConfig = cfg; | |
return cfg; | |
}) | |
); | |
} | |
// Если `canLoad => false` - генерируем событие `NavigationError` | |
return canLoadFails(route); | |
}) | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment