/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { Compiler, inject, Injectable, InjectionToken, NgModuleFactory } from '@angular/core'; import { ConnectableObservable, from, of, Subject } from 'rxjs'; import { finalize, map, mergeMap, refCount, tap } from 'rxjs/operators'; import { wrapIntoObservable } from './utils/collection'; import { assertStandalone, standardizeConfig, validateConfig } from './utils/config'; import * as i0 from "@angular/core"; /** * The [DI token](guide/glossary/#di-token) for a router configuration. * * `ROUTES` is a low level API for router configuration via dependency injection. * * We recommend that in almost all cases to use higher level APIs such as `RouterModule.forRoot()`, * `provideRouter`, or `Router.resetConfig()`. * * @publicApi */ export const ROUTES = new InjectionToken('ROUTES'); export class RouterConfigLoader { constructor() { this.componentLoaders = new WeakMap(); this.childrenLoaders = new WeakMap(); this.compiler = inject(Compiler); } loadComponent(route) { if (this.componentLoaders.get(route)) { return this.componentLoaders.get(route); } else if (route._loadedComponent) { return of(route._loadedComponent); } if (this.onLoadStartListener) { this.onLoadStartListener(route); } const loadRunner = wrapIntoObservable(route.loadComponent()) .pipe(map(maybeUnwrapDefaultExport), tap(component => { if (this.onLoadEndListener) { this.onLoadEndListener(route); } (typeof ngDevMode === 'undefined' || ngDevMode) && assertStandalone(route.path ?? '', component); route._loadedComponent = component; }), finalize(() => { this.componentLoaders.delete(route); })); // Use custom ConnectableObservable as share in runners pipe increasing the bundle size too much const loader = new ConnectableObservable(loadRunner, () => new Subject()).pipe(refCount()); this.componentLoaders.set(route, loader); return loader; } loadChildren(parentInjector, route) { if (this.childrenLoaders.get(route)) { return this.childrenLoaders.get(route); } else if (route._loadedRoutes) { return of({ routes: route._loadedRoutes, injector: route._loadedInjector }); } if (this.onLoadStartListener) { this.onLoadStartListener(route); } const moduleFactoryOrRoutes$ = loadChildren(route, this.compiler, parentInjector, this.onLoadEndListener); const loadRunner = moduleFactoryOrRoutes$.pipe(finalize(() => { this.childrenLoaders.delete(route); })); // Use custom ConnectableObservable as share in runners pipe increasing the bundle size too much const loader = new ConnectableObservable(loadRunner, () => new Subject()) .pipe(refCount()); this.childrenLoaders.set(route, loader); return loader; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterConfigLoader, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterConfigLoader, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterConfigLoader, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }] }); /** * Executes a `route.loadChildren` callback and converts the result to an array of child routes and * an injector if that callback returned a module. * * This function is used for the route discovery during prerendering * in @angular-devkit/build-angular. If there are any updates to the contract here, it will require * an update to the extractor. */ export function loadChildren(route, compiler, parentInjector, onLoadEndListener) { return wrapIntoObservable(route.loadChildren()) .pipe(map(maybeUnwrapDefaultExport), mergeMap((t) => { if (t instanceof NgModuleFactory || Array.isArray(t)) { return of(t); } else { return from(compiler.compileModuleAsync(t)); } }), map((factoryOrRoutes) => { if (onLoadEndListener) { onLoadEndListener(route); } // This injector comes from the `NgModuleRef` when lazy loading an `NgModule`. There is // no injector associated with lazy loading a `Route` array. let injector; let rawRoutes; let requireStandaloneComponents = false; if (Array.isArray(factoryOrRoutes)) { rawRoutes = factoryOrRoutes; requireStandaloneComponents = true; } else { injector = factoryOrRoutes.create(parentInjector).injector; // When loading a module that doesn't provide `RouterModule.forChild()` preloader // will get stuck in an infinite loop. The child module's Injector will look to // its parent `Injector` when it doesn't find any ROUTES so it will return routes // for it's parent module instead. rawRoutes = injector.get(ROUTES, [], { optional: true, self: true }).flat(); } const routes = rawRoutes.map(standardizeConfig); (typeof ngDevMode === 'undefined' || ngDevMode) && validateConfig(routes, route.path, requireStandaloneComponents); return { routes, injector }; })); } function isWrappedDefaultExport(value) { // We use `in` here with a string key `'default'`, because we expect `DefaultExport` objects to be // dynamically imported ES modules with a spec-mandated `default` key. Thus we don't expect that // `default` will be a renamed property. return value && typeof value === 'object' && 'default' in value; } function maybeUnwrapDefaultExport(input) { // As per `isWrappedDefaultExport`, the `default` key here is generated by the browser and not // subject to property renaming, so we reference it with bracket access. return isWrappedDefaultExport(input) ? input['default'] : input; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyX2NvbmZpZ19sb2FkZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi9wYWNrYWdlcy9yb3V0ZXIvc3JjL3JvdXRlcl9jb25maWdfbG9hZGVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBQyxRQUFRLEVBQXVCLE1BQU0sRUFBRSxVQUFVLEVBQWUsY0FBYyxFQUFZLGVBQWUsRUFBTyxNQUFNLGVBQWUsQ0FBQztBQUM5SSxPQUFPLEVBQUMscUJBQXFCLEVBQUUsSUFBSSxFQUFjLEVBQUUsRUFBRSxPQUFPLEVBQUMsTUFBTSxNQUFNLENBQUM7QUFDMUUsT0FBTyxFQUFDLFFBQVEsRUFBRSxHQUFHLEVBQUUsUUFBUSxFQUFFLFFBQVEsRUFBRSxHQUFHLEVBQUMsTUFBTSxnQkFBZ0IsQ0FBQztBQUd0RSxPQUFPLEVBQUMsa0JBQWtCLEVBQUMsTUFBTSxvQkFBb0IsQ0FBQztBQUN0RCxPQUFPLEVBQUMsZ0JBQWdCLEVBQUUsaUJBQWlCLEVBQUUsY0FBYyxFQUFDLE1BQU0sZ0JBQWdCLENBQUM7O0FBSW5GOzs7Ozs7Ozs7R0FTRztBQUNILE1BQU0sQ0FBQyxNQUFNLE1BQU0sR0FBRyxJQUFJLGNBQWMsQ0FBWSxRQUFRLENBQUMsQ0FBQztBQUs5RCxNQUFNLE9B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ludG9PYnNlcnZhYmxlKHJvdXRlLmxvYWRDb21wb25lbnQhKCkpXG4gICAgICAgICAgICAgICAgICAgICAgICAgICAucGlwZShcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXAobWF5YmVVbndyYXBEZWZhdWx0RXhwb3J0KSxcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB0YXAoY29tcG9uZW50ID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICh0aGlzLm9uTG9hZEVuZExpc3RlbmVyKSB7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMub25Mb2FkRW5kTGlzdGVuZXIocm91dGUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKHR5cGVvZiBuZ0Rldk1vZGUgPT09ICd1bmRlZmluZWQnIHx8IG5nRGV2TW9kZSkgJiZcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhc3NlcnRTdGFuZGFsb25lKHJvdXRlLnBhdGggPz8gJycsIGNvbXBvbmVudCk7XG4gICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICByb3V0ZS5fbG9hZGVkQ29tcG9uZW50ID0gY29tcG9uZW50O1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZpbmFsaXplKCgpID0+IHtcbiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMuY29tcG9uZW50TG9hZGVycy5kZWxldGUocm91dGUpO1xuICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0pLFxuICAgICAgICAgICAgICAgICAgICAgICAgICAgKTtcbiAgICAvLyBVc2UgY3VzdG9tIENvbm5lY3RhYmxlT2JzZXJ2YWJsZSBhcyBzaGFyZSBpbiBydW5uZXJzIHBpcGUgaW5jcmVhc2luZyB0aGUgYnVu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