ionic3 项目 懒加载配置

配置懒加载须要如下几个步骤:html

1.给须要懒加载的页面配置module.ts;
2.在对应页面的.ts文件里增长@IonicPage()特性
3.在app.module.ts移除页面引用;
4.使用懒加载;
5.懒加载运行效果图;
1.配置module.ts

依次配置about.module.ts、contact.module.ts、home.module.ts、tabs.module.tsapp

about.module.tsionic

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { AboutPage } from './about';

@NgModule({
    declarations: [
        AboutPage,
    ],
    imports: [
        IonicPageModule.forChild(AboutPage),
    ],
})
export class AboutPageModule { }
配置完成后目录以下

2.增长@IonicPage()特性code

以about.ts为例,在@Component上方加上@IonicPage(),其余须要懒加载的页面也须要配置htm

3.在app.module.ts移除页面引用;

4.使用懒加载io

使用懒加载,只须要将以前的页面名字用引号引发来便可,对应的也不须要在顶部进行import导入class

tabs.tsangular

import { IonicPage } from 'ionic-angular';
import { Component } from '@angular/core';
@IonicPage()
@Component({
  templateUrl: 'tabs.html'
})
export class TabsPage {
  tab1Root = 'HomePage';
  tab2Root = 'ContactPage';
  tab3Root = 'AboutPage';
  constructor() {
  }
}
注意:当某个页面使用懒加载后,报错没有找到,缘由是tabs里面引入要加 双引号 tab2Root = "AboutPage";
相关文章
相关标签/搜索