0

アプリにログインした後、タブスメニューページにリダイレクトしたい。Ionic3でのログイン後のタブメニュー

ユーザーがログインボタンをクリックすると、アプリに最初にアクセスしたときにホームページのみが表示されます。アプリのtabsmenuのルックスをリフレッシュした後

enter image description here

enter image description here

どのように私はこの問題を解決することができますか?

app.component.ts

import {Component} from '@angular/core'; 
import {App, NavController, Platform} from 'ionic-angular'; 
import {StatusBar} from '@ionic-native/status-bar'; 
import {SplashScreen} from '@ionic-native/splash-screen'; 

import {TabsPage} from '../pages/tabs/tabs'; 
import {Login} from '../pages/login/login'; 

import firebase from 'firebase'; 

@Component({ 
    templateUrl: 'app.html' 
}) 
export class MyApp { 
    rootPage: any = TabsPage; 

    constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) { 

    // Initialize Firebase 
    let config = { 
     apiKey: "##", 
     authDomain: "#.firebaseapp.com", 
     databaseURL: "#.firebaseio.com", 
     projectId: "#", 
     storageBucket: "#.appspot.com", 
     messagingSenderId: "##" 
    }; 
    firebase.initializeApp(config); 
    firebase.auth().onAuthStateChanged((user) => { 

     if (!user) { 
      console.log("not login"); 
      this.rootPage = Login; 

     } else { 
      console.log("login"); 
      this.rootPage = TabsPage; 
     } 

     } 
    ); 

    platform.ready().then(() => { 
     // Okay, so the platform is ready and our plugins are available. 
     // Here you can do any higher level native things you might need. 
     statusBar.styleDefault(); 
     splashScreen.hide(); 
    }); 
    } 
} 
+0

あなたの質問は私にとっては明確ではありません。あなたのユースケースについての詳細情報を提供できますか? – Sampath

+0

私はログインページを持っており、ユーザーは電子メールとパスワードを入力しています。ログインボタンをクリックします。あなたが次の画像としてtabsmenuに回転すると、ユーザーログインに成功したアプリケーションは、選択されたタブメニュー 'Home'のみを表示します。アプリをリフレッシュまたは再オープンすると、選択したタブ「ホーム」のタブメニューが表示されます。 @Sampath – onurkaya

+0

ログイン成功機能では、rootpage = HomePageを設定しますか? – Duannx

答えて

0

私は私の問題を解決しました。これはloginUser関数の障害でした。私はthis.nav.setRoot(HomePage)を書いたのは、最初のログイン時にホームページに移動するからです。返信ありがとう!

loginUser(): void { 
     if (!this.loginForm.valid) { 
      console.log(this.loginForm.value); 
     } else { 
      this.authData.loginUser(this.loginForm.value.email, this.loginForm.value.password).then(authData => { 
       this.loading.dismiss().then(() => { 
        this.nav.setRoot(TabsPage); 
       }); 
      }, error => { 
       this.loading.dismiss().then(() => { 
        let alert = this.alertCtrl.create({ 
         message: error.message, 
         buttons: [ 
          { 
           text: "Ok", 
           role: 'cancel' 
          } 
         ] 
        }); 
        alert.present(); 
       }); 
      }); 

      this.loading = this.loadingCtrl.create(); 
      this.loading.present(); 
     } 
    } 
関連する問題