Skip to content

Instantly share code, notes, and snippets.

@phenomnomnominal
Created March 11, 2019 01:58
Show Gist options
  • Save phenomnomnominal/d37142697a8b91bc5d8fdba536877bfa to your computer and use it in GitHub Desktop.
Save phenomnomnominal/d37142697a8b91bc5d8fdba536877bfa to your computer and use it in GitHub Desktop.
export function listLazyRoutes(
moduleMeta: CompileNgModuleMetadata, reflector: StaticReflector): LazyRoute[] {
const allLazyRoutes: LazyRoute[] = [];
for (const {provider, module} of moduleMeta.transitiveModule.providers) {
if (tokenReference(provider.token) === reflector.ROUTES) {
const loadChildren = _collectLoadChildren(provider.useValue);
for (const route of loadChildren) {
allLazyRoutes.push(parseLazyRoute(route, reflector, module.reference));
}
}
}
return allLazyRoutes;
}
export function parseLazyRoute(
route: string, reflector: StaticReflector, module?: StaticSymbol): LazyRoute {
const [routePath, routeName] = route.split('#');
const referencedModule = reflector.resolveExternalReference(
{
moduleName: routePath,
name: routeName,
},
module ? module.filePath : undefined);
return {route: route, module: module || referencedModule, referencedModule};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment