Preloading all modules is quite an extreme approach and might not always be desirable. For instance, you don't want to preload lazy routes a user might not even have access to. Therefore, in this lesson we're going to have a look at how to define a custom preloading strategy in Angular.

custom-preloader.ts:

import { PreloadingStrategy, Route } from '@angular/router';
import { Observable, of } from 'rxjs';
import { Injectable } from '@angular/core'; @Injectable({
providedIn: 'root'
})
export class CustomPreloader implements PreloadingStrategy {
preload(route: Route, load: Function): Observable<any> {
if (route.data && route.data['preload']) {
return load();
} else {
return of(null);
}
}
}
import { CustomPreloader } from './custom-preloader';

@NgModule({
declarations: [AppComponent, HomeComponent],
imports: [
BrowserModule,
MatSidenavModule,
BrowserAnimationsModule,
RouterModule.forRoot(
[
{
path: '',
component: HomeComponent
},
{
path: 'nyan',
loadChildren: () =>
import('./nyan/nyan.module').then(m => m.NyanModule),
data: {
preload: true
}
},
{
path: 'about',
loadChildren: () =>
import('./about/about.module').then(m => m.AboutModule)
}
],
{
preloadingStrategy: CustomPreloader //PreloadAllModules
}
)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}

[Angular 8] Implement a Custom Preloading Strategy with Angular的更多相关文章

  1. How to: Implement a Custom Base Persistent Class 如何:实现自定义持久化基类

    XAF ships with the Business Class Library that contains a number of persistent classes ready for use ...

  2. angular的跨域(angular百度下拉提示模拟)和angular选项卡

    1.angular中$http的服务: $http.get(url,{params:{参数}}).success().error(); $http.post(url,{params:{参数}}).su ...

  3. angular 2+ 变化检测系列三(Zone.js在Angular中的应用)

    在系列一中,我们提到Zone.js,Zones是一种执行上下文,它允许我们设置钩子函数在我们的异步任务的开始位置和结束位置,Angular正是利用了这一特性从而实现了变更检测. Zones.js非常适 ...

  4. 【Angular JS】正确调用JQuery与Angular JS脚本 - 修复Warning: Tired to load angular more than once

    自己正在做一个小网站,使用Angular JS + Express JS + Mongo DB,在开发过程中,遇到一些问题,所以整理出来.希望对大家都有帮助. 这是今天解决的一个问题,Angular ...

  5. [Angular] Implement a custom form component by using control value accessor

    We have a form component: <label> <h3>Type</h3> <workout-type formControlName=& ...

  6. [Angular Directive] Implement Structural Directive Data Binding with Context in Angular

    Just like in *ngFor, you're able to pass in data into your own structural directives. This is done b ...

  7. How to implement a custom type for NHibernate property

    http://blog.miraclespain.com/archive/2008/Mar-18.html <?xml version="1.0" encoding=&quo ...

  8. [Angular 2] Filter items with a custom search Pipe in Angular 2

    This lessons implements the Search Pipe with a new SearchBox component so you can search through eac ...

  9. How to implement a custom PropertyEditor so that it supports Appearance rules provided by the ConditionalAppearance module

    https://www.devexpress.com/Support/Center/Question/Details/T505528/how-to-implement-a-custom-propert ...

随机推荐

  1. [转帖]Linux系统进程的知识总结,进程与线程之间的纠葛...

    Linux系统进程的知识总结,进程与线程之间的纠葛... https://cloud.tencent.com/developer/article/1500509 当一个程序开始执行后,在开始执行到执行 ...

  2. java当中JDBC当中请给出一个DataSource的单态模式(SingleTon)HelloWorld例子

    [学习笔记] 2.DataSource的单态模式(SingleTon)程序 咱们还接着上面的例子来说.1万个人要看书.千万确保要只建立一个图书馆.要是一不留神,建了两个或三个图书馆,那可就亏大发了.对 ...

  3. 《C++语言程序设计》初学者必备教材

    很多刚开始学习C++语言的同学,都会遇到一个问题:很多教材都不适合零基础的初学者.它们有的枯燥乏味,让人难以消化吸收,有的层次结构混乱,很难理清楚知识点,有的更是难度太大,没有代码的过渡,就开始讲解算 ...

  4. PowerBuilder学习笔记之8.5高级窗口控件

    1.列表框控件 列表框控件(ListBox).图片列表框控件(PictureListBox).下拉列表框控件(DropDownListBox)以及下拉图片列表框控件(DropDownPictureLi ...

  5. VS2015编译Teamtalk的Windows客户端(转)

    原文链接:https://blog.csdn.net/qtstar/article/details/54732581 一.(首先要把teamtalk整个项目download下来或git一个副本下来)打 ...

  6. JAVA 插入注解处理器

    JDK1.5后,Java语言提供了对注解(Annotation)的支持 JDK1.6中提供一组插件式注解处理器的标准API,可以实现API自定义注解处理器,干涉编译器的行为. 在这里,注解处理器可以看 ...

  7. R_数据视觉化处理_初阶_02

    通过数据创建一幅简单的图像, #Crate a easy photopdf("mygraph.pdf") attach(mtcars) plot(wt,mpg) abline(lm ...

  8. shim和polyfill 区别解释

    polyfill 是 shim 的一种.shim 是将不同 api 封装成一种,比如 jQuery 的 $.ajax 封装了 XMLHttpRequest 和 IE 用 ActiveXObject 方 ...

  9. pc端vue 滚动到底部翻页

    html: <div class="list" ref="scrollTopList"> <div class="listsmall ...

  10. 对于Element-ui分页进行再次的封装使用

    这是我项目的分页的目录结构,话不多说,直接上代码. <template> <div class="pagination-container"> <el ...