使用 Ionic Framework 设置新的主页



我正在使用离子框架来构建和应用。默认情况下,主目录设置为主页,但我已经开始构建,现在想在此原始主页之前添加一个登录页面。无论如何,我可以将新的登录页面设置为应用程序的起始页吗?谢谢。

您可以在

src/app/app.component.ts中执行此操作。例如

import { Component } from '@angular/core';
import { LoginPage } from '...';
// other imports
@Component({
  template: `<ion-nav [root]="rootPage"></ion-nav>`
})
export class MyApp {
  public rootPage: any;
  constructor(
    platform: Platform
  ) {
    platform.ready().then(() => {
      StatusBar.hide();
      Splashscreen.hide();
      this.rootPage = LoginPage;    // don't forget to import this page
    });
  }
}

MyApp 中使用rootPage

export class MyApp {
  rootPage:any = 'YourLoginPage';
}

对于登录场景,您可以使用rootPage属性,

在声明期间,例如

rootPage:any = Dashboard;//import { Dashboard } from '../pages/dashboard/dashboard'

或在方法中,例如

this.rootPage = Dashboard

稍后,一旦登录后获得成功响应,您可以使用 App 对象设置应用程序的根页面,例如

import { App } from 'ionic/angular'
import { Dashboard } from '../pages/dashboard/dashboaard'

//inject in contructor
constructor(private app:App){}

//then in method where login success is received
login(){
 if(loginValid){
   this.app.getRootNav().setRoot(Dashboard);//in this way you will not have back button for new page
 }
}

希望对您有所帮助。 :)

最新更新