2017-06-20 80 views
0

我正在使用離子框架構建和應用程序。默認情況下,主目錄設置爲主頁,但我已經開始構建,現在想在此原始主頁之前添加登錄頁面。無論如何,我可以設置新的登錄頁面作爲應用程序的起始頁面?謝謝。使用Ionic Framework設置新主頁

回答

1

你可以在你的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 
    }); 
  } 
} 
1

使用rootPage在MyApp的

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

對於登錄情況下,你可以使用rootPage財產申報過程中

,像

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

或方法中,像

this.rootPage = Dashboard 

後來一旦你登錄後全成響應,您可以設置使用應用對象的應用程序的rootPage,像

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 
} 
} 

希望它能幫助。 :)