简体   繁体   English

尝试导航至选项卡页遇到意外(承诺)时,出现此错误:无效链接:TabsPage

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

I have a question about navigating to theTabs page if the user is logged in. In the last code block the navigation to the LoginPage (if there is no users in the firebase ) works, but if the user is logged in then if should be directed to the TabsPage in which it is giving me an error of " Uncaught (in promise): invalid link: TabsPage". 我有一个关于如果用户登录到导航表页面的问题。在最后一个代码块中,可以导航到LoginPage(如果firebase中没有用户),但是如果用户已登录,则应该定向到TabsPage,在其中它给我一个错误:“未捕获(承诺):无效链接:TabsPage”。

*This is my app.component.ts file** *这是我的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();
  }
});



}
}

This is my tabs.ts 这是我的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() {

}



}

You are using syntax with strings in your app.component.ts as if your app uses lazy loading of components/pages. 您正在app.component.ts中使用带有字符串的语法,就像您的应用程序使用组件/页面的延迟加载一样。

But based on your imports (the fact you are importing components) means you are using non lazy loading approach. 但是基于您的导入(实际上是在导入组件)意味着您正在使用非延迟加载方法。

Fix it by assigning components and not strings: 通过分配组件而不是字符串来修复它:

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.

相关问题 错误错误:未捕获(承诺):无效链接:SosPopPage - ERROR Error: Uncaught (in promise): invalid link: SosPopPage 错误:未捕获(承诺):无效链接:ProductListComponent - Error: Uncaught (in promise): invalid link: ProductListComponent 我试图导航到我的发货页面,但我一直收到此错误 - Im trying to navigate to my shipping page but i keep getting this error 本机反应:我尝试导航到某个页面时出现什么错误? - react native: what is the error while i trying to navigate to some page? Ionic Lazy loading错误:未捕获(在承诺中):无效链接SecondPage - Ionic Lazy loading Error: Uncaught (in promise): invalid link SecondPage 为什么我会收到“Uncaught(in Promise)”错误呢? - Why am I getting “Uncaught(in Promise)” error with then? 我是新来的反应,我已经坚持了一段时间。 不断收到未捕获的错误 - I'm new to react and i've been stuck on this for a while. Keep getting a uncaught error 未捕获(承诺中)错误:无效地址 - Uncaught (in promise) Error: invalid address 我有这个错误 Uncaught (in promise) TypeError: Failed to fetch - i have this error Uncaught (in promise) TypeError: Failed to fetch 我一直在尝试安装或创建一个 React 应用程序,但我一直收到此错误消息 - I have been trying to install or create a react app but I kept getting this error message
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM