[6a3a178] | 1 | /**
|
---|
| 2 | * @license
|
---|
| 3 | * Copyright Google LLC All Rights Reserved.
|
---|
| 4 | *
|
---|
| 5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 6 | * found in the LICENSE file at https://angular.io/license
|
---|
| 7 | */
|
---|
| 8 | import { Compiler, Injectable, Injector, NgModuleFactoryLoader, NgModuleRef } from '@angular/core';
|
---|
| 9 | import { from, of } from 'rxjs';
|
---|
| 10 | import { catchError, concatMap, filter, map, mergeAll, mergeMap } from 'rxjs/operators';
|
---|
| 11 | import { NavigationEnd, RouteConfigLoadEnd, RouteConfigLoadStart } from './events';
|
---|
| 12 | import { Router } from './router';
|
---|
| 13 | import { RouterConfigLoader } from './router_config_loader';
|
---|
| 14 | /**
|
---|
| 15 | * @description
|
---|
| 16 | *
|
---|
| 17 | * Provides a preloading strategy.
|
---|
| 18 | *
|
---|
| 19 | * @publicApi
|
---|
| 20 | */
|
---|
| 21 | export class PreloadingStrategy {
|
---|
| 22 | }
|
---|
| 23 | /**
|
---|
| 24 | * @description
|
---|
| 25 | *
|
---|
| 26 | * Provides a preloading strategy that preloads all modules as quickly as possible.
|
---|
| 27 | *
|
---|
| 28 | * ```
|
---|
| 29 | * RouterModule.forRoot(ROUTES, {preloadingStrategy: PreloadAllModules})
|
---|
| 30 | * ```
|
---|
| 31 | *
|
---|
| 32 | * @publicApi
|
---|
| 33 | */
|
---|
| 34 | export class PreloadAllModules {
|
---|
| 35 | preload(route, fn) {
|
---|
| 36 | return fn().pipe(catchError(() => of(null)));
|
---|
| 37 | }
|
---|
| 38 | }
|
---|
| 39 | /**
|
---|
| 40 | * @description
|
---|
| 41 | *
|
---|
| 42 | * Provides a preloading strategy that does not preload any modules.
|
---|
| 43 | *
|
---|
| 44 | * This strategy is enabled by default.
|
---|
| 45 | *
|
---|
| 46 | * @publicApi
|
---|
| 47 | */
|
---|
| 48 | export class NoPreloading {
|
---|
| 49 | preload(route, fn) {
|
---|
| 50 | return of(null);
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | /**
|
---|
| 54 | * The preloader optimistically loads all router configurations to
|
---|
| 55 | * make navigations into lazily-loaded sections of the application faster.
|
---|
| 56 | *
|
---|
| 57 | * The preloader runs in the background. When the router bootstraps, the preloader
|
---|
| 58 | * starts listening to all navigation events. After every such event, the preloader
|
---|
| 59 | * will check if any configurations can be loaded lazily.
|
---|
| 60 | *
|
---|
| 61 | * If a route is protected by `canLoad` guards, the preloaded will not load it.
|
---|
| 62 | *
|
---|
| 63 | * @publicApi
|
---|
| 64 | */
|
---|
| 65 | export class RouterPreloader {
|
---|
| 66 | constructor(router, moduleLoader, compiler, injector, preloadingStrategy) {
|
---|
| 67 | this.router = router;
|
---|
| 68 | this.injector = injector;
|
---|
| 69 | this.preloadingStrategy = preloadingStrategy;
|
---|
| 70 | const onStartLoad = (r) => router.triggerEvent(new RouteConfigLoadStart(r));
|
---|
| 71 | const onEndLoad = (r) => router.triggerEvent(new RouteConfigLoadEnd(r));
|
---|
| 72 | this.loader = new RouterConfigLoader(moduleLoader, compiler, onStartLoad, onEndLoad);
|
---|
| 73 | }
|
---|
| 74 | setUpPreloading() {
|
---|
| 75 | this.subscription =
|
---|
| 76 | this.router.events
|
---|
| 77 | .pipe(filter((e) => e instanceof NavigationEnd), concatMap(() => this.preload()))
|
---|
| 78 | .subscribe(() => { });
|
---|
| 79 | }
|
---|
| 80 | preload() {
|
---|
| 81 | const ngModule = this.injector.get(NgModuleRef);
|
---|
| 82 | return this.processRoutes(ngModule, this.router.config);
|
---|
| 83 | }
|
---|
| 84 | /** @nodoc */
|
---|
| 85 | ngOnDestroy() {
|
---|
| 86 | if (this.subscription) {
|
---|
| 87 | this.subscription.unsubscribe();
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | processRoutes(ngModule, routes) {
|
---|
| 91 | const res = [];
|
---|
| 92 | for (const route of routes) {
|
---|
| 93 | // we already have the config loaded, just recurse
|
---|
| 94 | if (route.loadChildren && !route.canLoad && route._loadedConfig) {
|
---|
| 95 | const childConfig = route._loadedConfig;
|
---|
| 96 | res.push(this.processRoutes(childConfig.module, childConfig.routes));
|
---|
| 97 | // no config loaded, fetch the config
|
---|
| 98 | }
|
---|
| 99 | else if (route.loadChildren && !route.canLoad) {
|
---|
| 100 | res.push(this.preloadConfig(ngModule, route));
|
---|
| 101 | // recurse into children
|
---|
| 102 | }
|
---|
| 103 | else if (route.children) {
|
---|
| 104 | res.push(this.processRoutes(ngModule, route.children));
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | return from(res).pipe(mergeAll(), map((_) => void 0));
|
---|
| 108 | }
|
---|
| 109 | preloadConfig(ngModule, route) {
|
---|
| 110 | return this.preloadingStrategy.preload(route, () => {
|
---|
| 111 | const loaded$ = route._loadedConfig ? of(route._loadedConfig) :
|
---|
| 112 | this.loader.load(ngModule.injector, route);
|
---|
| 113 | return loaded$.pipe(mergeMap((config) => {
|
---|
| 114 | route._loadedConfig = config;
|
---|
| 115 | return this.processRoutes(config.module, config.routes);
|
---|
| 116 | }));
|
---|
| 117 | });
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | RouterPreloader.decorators = [
|
---|
| 121 | { type: Injectable }
|
---|
| 122 | ];
|
---|
| 123 | RouterPreloader.ctorParameters = () => [
|
---|
| 124 | { type: Router },
|
---|
| 125 | { type: NgModuleFactoryLoader },
|
---|
| 126 | { type: Compiler },
|
---|
| 127 | { type: Injector },
|
---|
| 128 | { type: PreloadingStrategy }
|
---|
| 129 | ];
|
---|
| 130 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicm91dGVyX3ByZWxvYWRlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uL3BhY2thZ2VzL3JvdXRlci9zcmMvcm91dGVyX3ByZWxvYWRlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O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