āthisā is different inside āthen(function)ā ā¦
If you are trying this app on browser it wonāt work because of this.platform.ready works only on android or ios device. you should write it in construct or inside ngOnInit()
Iām struggling with the same issue (FYI: Iām new to Ionic v2, so please be gentle ;-)). Within the constructor of the main component (using ionicBootstrap to initialize the app) I try to set the rootPage based on condition. The condition is met for sure, I verified by logs. Hereās the simplified code:
As a side note, in Typescript when you use the fat arrows (i.e. =>) you donāt need to do the whole let self = this; trick. Fat arrows will automagically do that for you. Which is to say, you can safely use this inside of fat arrow functions.
As for the question presented, this is just a guess but perhaps you canāt set the rootPage inside of platform ready callback? This is just a guess based off of my code, which doesnāt set it inside of the platform ready callback.
Thanks for the sidenote and your thoughts. Itās actually working when putting it outside of the platform ready callback. Unfortunately, Iāve the wait for a plugin which decides where to navigate to. Will keep you posted.
Excellent, @SigmundFroyd, thanks! The solution with using ViewChild and setRoot is working fine. Although I had to use self = this, the reference of this was being changed within the callback.
Hi, I got multiple conditional rootPages, I tried both above, both got some issue.
export class MyApp {
rootPage: any = null;
constructor(public platform: Platform) {
platform.ready().then(() => {
switch (condition) {
case xxx:
this.rootPage = LoginPage;
break;
case yyy:
this.rootPage = HomePage;
break;
// ....
});
}
}
In this way, I got blank first screen occasionally, app got resumed after several reboot. I inspected the page, there was no rootPage under ion-nav which told me rootPage was not successfully set, sometimes.
And I also tried using navCtrl.setRoot(whichPage), the blank first screen gone, the the bottom tool bar lost response for HomePage which used a toolbar in the bottom of screen, quite weird.