我在尝试导航到选项卡页面时遇到了这个错误Uncaught(承诺):无效链接:TabsPage



如果用户登录,我有一个关于导航到Tabs页面的问题。在最后一个代码块中,导航到LoginPage(如果firebase中没有用户(是可行的,但如果用户登录了,那么如果应该指向TabsPage,它会在其中给我一个错误"Uncaught(in promise(:无效链接: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();
}
});

}
}

这是我的标签。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();
}
});

最新更新