diff --git a/src/index.ts b/src/index.ts index f88c89e48a..9d5338c0ef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,7 +33,7 @@ import { Keyboard } from './platform/keyboard'; import { LoadingController } from './components/loading/loading-controller'; import { MenuController } from './components/menu/menu-controller'; import { ModalController } from './components/modal/modal-controller'; -import { ModuleLoader, provideModuleLoader, LAZY_LOADED_TOKEN } from './util/module-loader'; +import { ModuleLoader, provideModuleLoader, setupPreloading, LAZY_LOADED_TOKEN } from './util/module-loader'; import { NgModuleLoader } from './util/ng-module-loader'; import { PickerController } from './components/picker/picker-controller'; import { Platform, setupPlatform } from './platform/platform'; @@ -591,6 +591,7 @@ export class IonicModule { { provide: APP_INITIALIZER, useFactory: registerModeConfigs, deps: [ Config ], multi: true }, { provide: APP_INITIALIZER, useFactory: setupProvideEvents, deps: [ Platform, DomController ], multi: true }, { provide: APP_INITIALIZER, useFactory: setupTapClick, deps: [ Config, Platform, DomController, App, NgZone, GestureController ], multi: true }, + { provide: APP_INITIALIZER, useFactory: setupPreloading, deps: [ DeepLinkConfigToken, ModuleLoader ], multi: true }, // useClass // { provide: HAMMER_GESTURE_CONFIG, useClass: IonicGestureConfig }, diff --git a/src/util/module-loader.ts b/src/util/module-loader.ts index e9857618e3..32524c2520 100644 --- a/src/util/module-loader.ts +++ b/src/util/module-loader.ts @@ -1,4 +1,5 @@ import { ComponentFactoryResolver, Injectable, Injector, OpaqueToken, Type } from '@angular/core'; +import { DeepLinkConfig } from '../navigation/nav-util'; import { NgModuleLoader } from './ng-module-loader'; export const LAZY_LOADED_TOKEN = new OpaqueToken('LZYCMP'); @@ -47,3 +48,16 @@ export interface LoadedModule { componentFactoryResolver: ComponentFactoryResolver; component: Type; }; + + +/** + * @private + */ +export function setupPreloading(deeplinkConfig: DeepLinkConfig, moduleLoader: ModuleLoader) { + return function() { + const linksToLoad = deeplinkConfig.links.filter(link => !!link.loadChildren); + for (const link of linksToLoad) { + moduleLoader.load(link.loadChildren); + } + }; +}