2017-09-15 26 views
0

當用戶打開應用程序(如果已經有會話對象的話),那麼應用程序應該打開標籤頁而不是註冊。Ionic 3 - 如果會話存在加載標籤頁而不是註冊頁

什麼是實現這個目標的最好方法。我正在使用ionic-start-super模板。 https://github.com/ionic-team/ionic-starter-super

我在想只檢查一個會話是否存在於註冊頁面的構造函數中,如果它確實存在,那麼它會將標籤頁面設置爲如下所示的根。

this.storage.get('user').then((user) => { 

      this.user = user; 

      if (this.user) { 
       this.navCtrl.setRoot(TabsPage); 

      } 
}); 

林想知道是否有更有效的方法。

回答

0

你可以使用你的腳本里面ionViewCanEnter()這樣的 -

ionViewCanEnter() { 
    this.storage.get('user').then((user) => { 
     this.user = user; 
     if (this.user) { 
      this.navCtrl.setRoot(TabsPage); 
     } 
    }); 
} 
相關問題