简体   繁体   中英

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".

*This is my app.component.ts file**

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

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.

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();
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM