Hello, I’m trying to figure out why my Ionic 3 app’s homepage loads 4 times. Basically it’s an app with 4 tabs, the first tab being the homepage. Here’s part of the constructor of app.component.ts
platform.ready()
.then(() => this.initializeFB())
.then(() => this.initializeHockeyApp())
.then(() => this.setUserForMenu())
.then(() => this.checkNetwork())
.then(() => this.initializeTheApp())
.then(() => this.initializeFirebase())
.then(() => this.navigation.initRootNav(this.nav))
.then(() => this.setRoot());
Each of those functions are defined underneath, such as
private async initializeFB()
{ console.log("initializeFb");
const fbConf = {
apiKey: sfConfig.firebase.apiKey,
authDomain: sfConfig.firebase.authDomain,
databaseURL: sfConfig.firebase.databaseURL,
storageBucket: sfConfig.firebase.storageBucket,
messagingSenderId: sfConfig.firebase.messagingSenderId
};
await firebase.initializeApp(fbConf);
const unsubscribe = await firebase.auth().onAuthStateChanged(user => {
if (!user){
console.log("Going to login page");
this.rootPage = 'Login';
unsubscribe();
} else {
console.log("Going to tabsHome page");
this.rootPage = 'TabsHome';
unsubscribe();
}
});
console.log("/initializeFb");
}
/***
... the other functions...
**/
private async setRoot()
{
console.log("setRoot");
//So app doesn't close when hockey app activities close
//This also has a side effect of unable to close the app when on the rootPage and using the back button.
//Back button will perform as normal on other pages and pop to the previous page.
this.platform.registerBackButtonAction(async x => {
let nav = this.app.getRootNav();
if (nav.canGoBack()) {
await nav.pop();
} else {
await nav.setRoot(this.rootPage);
}
}); //registerbackbutton
console.log("/setRoot");
}
The tabs home contains the 4 tabs, first being home.ts. Home.ts has console.log(“hello home”) among other things.
When the app loads, “hello home” is logged 4 different times! The only time it should ever load is within the setRoot() function above, but it seems to be called at random times.
How do I force it to call just once in setRoot()?
Thanks.