天天看點

更新到ionic3 Lazy Loading懶加載,ionic3建立頁面

ionic2 CLI建立頁面指令:

ionic g page home

生成:

home.html,home.ts,home.scss三個檔案

ionic更新到到3.+之後,

ionic g page home或者ionic generate page home

生成:

home.html,home.ts,home.scss三個檔案之外,

還會生成home.module.ts,内容如下:

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { HomePage } from './open-store';

@NgModule({
  declarations: [
    HomePage,
  ],
  imports: [
    IonicPageModule.forChild(HomePage),
  ],
  exports: [
    HomePage
  ],

})
export class HomePage {}
           

其中 @NgModule 表明此頁面為單獨的module,就是在需要時才加載的module,而不是ionic2所有的頁面都在AppModule裡,這就是所謂的懶加載了

同時,也不用像ionic2之前,不需要在app.module.ts中declarations,entryComponents添加聲明每個頁面了。

引用:

以前是

import { HomePage } from '../home/home';

this.navCtrl.push(HomePage);
           

現在更簡單了, 直接用string類型就可以

this.navCtrl.push('HomePage');