How to do it...

  1. To take advantage of route preloading, we first have to turn it on in our root router configuration. By default, the Angular router comes with one of two preloading strategies; preload everything with PreloadAllModules, or preload nothing with NoPreloading:
...
import {RouterModule, PreloadAllModules} from '@angular/router';

@NgModule({
...
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule.forRoot(ROUTES, { preloadingStrategy: PreloadAllModules })
],
...
})
export class AppModule { }
  1. Now that we have enabled preloading on our root router configuration, we have to enable lazy loading modules. For our router configuration, we must provide our lazy loaded child module in a string format using the loadChildren property. We also must provide the name of the module class itself to be invoked by the preloading strategy:
...
const ROUTES = [{
path: "posts"
loadChildren: "posts/posts.module#postModule"
}];
...
  1. With this configuration in place, the application will automatically start preloading this posts, lazy loading module after it initially bootstraps the Angular application.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.203.107