如何在 Ionic With Angular 中基于本地存储值加载页面

How to load a Page based on local storage value, in Ionic With Angular

我想根据构造函数中的 if 条件的结果显示 RegisterPage。我是 Ionic 和 Angular 的新手。谁能建议我做这个需求。

app.component.ts

  export class MyApp {
    @ViewChild(Nav) navCtrl: Nav;
    rootPage:any = RegisterPage; 
    constructor(platform: Platform) {
    platform.ready().then(() => {
      if(localStorage["User"]||localStorage["Tenant"]===null){      
      this.navCtrl.push(RegisterPage);             //call reg form
      }
        else{
        //call login form        
        }
    });
  }
}

app.html

<ion-nav #mainContent [root]="rootPage"></ion-nav>
 platform.ready().then(() => {
          if(localStorage["User"]||localStorage["Tenant"]===null)
           {
            this.rootPage = RegisterPage; 
          }
          else{
            this.rootPage = LoginPage;
         }
 });

试试这个