Skip to content

Instantly share code, notes, and snippets.

@arturovt
Last active March 20, 2019 21:25
Show Gist options
  • Save arturovt/d4d6f2682c0e752ea70d104bb19a9f1c to your computer and use it in GitHub Desktop.
Save arturovt/d4d6f2682c0e752ea70d104bb19a9f1c to your computer and use it in GitHub Desktop.
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