簡體   English   中英

嘗試導航至選項卡頁遇到意外(承諾)時,出現此錯誤:無效鏈接:TabsPage

[英]I have been getting this error while trying to navigate to the tabs page Uncaught (in promise): invalid link: TabsPage

我有一個關於如果用戶登錄到導航表頁面的問題。在最后一個代碼塊中,可以導航到LoginPage(如果firebase中沒有用戶),但是如果用戶已登錄,則應該定向到TabsPage,在其中它給我一個錯誤:“未捕獲(承諾):無效鏈接:TabsPage”。

*這是我的app.component.ts文件**

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { LoginPage } from '../pages/login/login';
import { UserprofilePage } from '../pages/userprofile/userprofile';
import { TabsPage } from '../pages/tabs/tabs';
import firebase from 'firebase/app';
import 'firebase/auth';
import { FIREBASE_CONFIG } from './credentials';




@Component({
templateUrl: 'app.html'
})
export class MyApp {


rootPage:any;


constructor(platform: Platform, statusBar: StatusBar, splashScreen: 
SplashScreen ) {
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();

});

if (!firebase.apps.length) {
    firebase.initializeApp(FIREBASE_CONFIG);
}
const unsubscribe = firebase.auth().onAuthStateChanged(user => {
  if (!user) { //if user doesn't exist
    this.rootPage = 'LoginPage';
    unsubscribe();
  } else { //if user is true, logged in
    this.rootPage= 'TabsPage';
    unsubscribe();
  }
});



}
}

這是我的tabs.ts

import { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { AboutPage } from '../about/about';
import { ContactPage } from '../contact/contact';
import { HomePage } from '../home/home';
import {UserprofilePage} from '../userprofile/userprofile';
import { IonicPage } from 'ionic-angular';


@Component({
templateUrl: 'tabs.html'
})
export class TabsPage {

tab1Root = HomePage;
tab2Root = UserprofilePage;
tab3Root = ContactPage;

constructor() {

}



}

您正在app.component.ts中使用帶有字符串的語法,就像您的應用程序使用組件/頁面的延遲加載一樣。

但是基於您的導入(實際上是在導入組件)意味着您正在使用非延遲加載方法。

通過分配組件而不是字符串來修復它:

const unsubscribe = firebase.auth().onAuthStateChanged(user => {
  if (!user) { //if user doesn't exist
    this.rootPage = LoginPage;
    unsubscribe();
  } else { //if user is true, logged in
    this.rootPage= TabsPage;
    unsubscribe();
  }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM