升级到ionic3 Lazy Loading懒加载,ionic3新建页面

原文出处:https://blog.csdn.net/u010564430/article/details/73776726
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');


 

猜你喜欢

转载自blog.csdn.net/chelen_jak/article/details/89242170