/** * @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, createEnvironmentInjector, EnvironmentInjector, Injectable } from '@angular/core'; import { from, of } from 'rxjs'; import { catchError, concatMap, filter, mergeAll, mergeMap } from 'rxjs/operators'; import { NavigationEnd } from './events'; import { Router } from './router'; import { RouterConfigLoader } from './router_config_loader'; import * as i0 from "@angular/core"; import * as i1 from "./router"; import * as i2 from "./router_config_loader"; /** * @description * * Provides a preloading strategy. * * @publicApi */ export class PreloadingStrategy { } /** * @description * * Provides a preloading strategy that preloads all modules as quickly as possible. * * ``` * RouterModule.forRoot(ROUTES, {preloadingStrategy: PreloadAllModules}) * ``` * * @publicApi */ export class PreloadAllModules { preload(route, fn) { return fn().pipe(catchError(() => of(null))); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PreloadAllModules, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PreloadAllModules, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: PreloadAllModules, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }] }); /** * @description * * Provides a preloading strategy that does not preload any modules. * * This strategy is enabled by default. * * @publicApi */ export class NoPreloading { preload(route, fn) { return of(null); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NoPreloading, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NoPreloading, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: NoPreloading, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }] }); /** * The preloader optimistically loads all router configurations to * make navigations into lazily-loaded sections of the application faster. * * The preloader runs in the background. When the router bootstraps, the preloader * starts listening to all navigation events. After every such event, the preloader * will check if any configurations can be loaded lazily. * * If a route is protected by `canLoad` guards, the preloaded will not load it. * * @publicApi */ export class RouterPreloader { constructor(router, compiler, injector, preloadingStrategy, loader) { this.router = router; this.injector = injector; this.preloadingStrategy = preloadingStrategy; this.loader = loader; } setUpPreloading() { this.subscription = this.router.events .pipe(filter((e) => e instanceof NavigationEnd), concatMap(() => this.preload())) .subscribe(() => { }); } preload() { return this.processRoutes(this.injector, this.router.config); } /** @nodoc */ ngOnDestroy() { if (this.subscription) { this.subscription.unsubscribe(); } } processRoutes(injector, routes) { const res = []; for (const route of routes) { if (route.providers && !route._injector) { route._injector = createEnvironmentInjector(route.providers, injector, `Route: ${route.path}`); } const injectorForCurrentRoute = route._injector ?? injector; const injectorForChildren = route._loadedInjector ?? injectorForCurrentRoute; // Note that `canLoad` is only checked as a condition that prevents `loadChildren` and not // `loadComponent`. `canLoad` guards only block loading of child routes by design. This // happens as a consequence of needing to descend into children for route matching immediately // while component loading is deferred until route activation. Because `canLoad` guards can // have side effects, we cannot execute them here so we instead skip preloading altogether // when present. Lastly, it remains to be decided whether `canLoad` should behave this way // at all. Code splitting and lazy loading is separate from client-side authorization checks // and should not be used as a security measure to prevent loading of code. if ((route.loadChildren && !route._loadedRoutes && route.canLoad === undefined) || (route.loadComponent && !route._loadedComponent)) { res.push(this.preloadConfig(injectorForCurrentRoute, route)); } if (route.children || route._loadedRoutes) { res.push(this.processRoutes(injectorForChildren, (route.children ?? route._loadedRoutes))); } } return from(res).pipe(mergeAll()); } preloadConfig(injector, route) { return this.preloadingStrategy.preload(route, () => { let loadedChildren$; if (route.loadChildren && route.canLoad === undefined) { loadedChildren$ = this.loader.loadChildren(injector, route); } else { loadedChildren$ = of(null); } const recursiveLoadChildren$ = loadedChildren$.pipe(mergeMap((config) => { if (config === null) { return of(void 0); } route._loadedRoutes = config.routes; route._loadedInjector = config.injector; // If the loaded config was a module, use that as the module/module injector going // forward. Otherwise, continue using the current module/module injector. return this.processRoutes(config.injector ?? injector, config.routes); })); if (route.loadComponent && !route._loadedComponent) { const loadComponent$ = this.loader.loadComponent(route); return from([recursiveLoadChildren$, loadComponent$]).pipe(mergeAll()); } else { return recursiveLoadChildren$; } }); } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterPreloader, deps: [{ token: i1.Router }, { token: i0.Compiler }, { token: i0.EnvironmentInjector }, { token: PreloadingStrategy }, { token: i2.RouterConfigLoader }], target: i0.ɵɵFactoryTarget.Injectable }); } static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterPreloader, providedIn: 'root' }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.2.12", ngImport: i0, type: RouterPreloader, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: function () { return [{ type: i1.Router }, { type: i0.Compiler }, { type: i0.EnvironmentInjector }, { type: PreloadingStrategy }, { type: i2.RouterConfigLoader }]; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyX3ByZWxvYWRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3JvdXRlci9zcmMvcm91dGVyX3ByZWxvYWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsUUFBUSxFQUFFLHlCQUF5QixFQUFFLG1CQUFtQixFQUFFLFVBQVUsRUFBWSxNQUFNLGVBQWUsQ0FBQztBQUM5RyxPQUFPLEVBQUMsSUFBSSxFQUFjLEVBQUUsRUFBZSxNQUFNLE1BQU0sQ0F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