After going from page1.ts to page2.ts successfully using a simple this.navCtrl.setRoot, I want to check on which page I am for some conditional styling of a component (TopNav) I am using in the page I am going to, however, when using
ionViewDidLoad() {
let view = this.navCtrl.getActive();
console.log("I am on: " + view.component.name);
}
It says “Page 1” (where i came from), until I have clicked once more on that button, only then it updates to the correct view (even though it shows page2 on the screen)… so weird
Any explanation? Am I perhaps using navigation in a wrong way? The way I understand it, setRoot is the correct way for me here, as the page I am going to is a separate part of the app (so I don’t want to use push). If I however don’t use push, but setRoot, do I have to check in a different way where I am?
PS I get the same behavior (showing old page) when I execute above in the constructor function directly. … reason why I wanted to use ionViewDidLoad is because it supposedly gets executed at all times (even when cached)…
Also, documentation appears misleading/confusing: “Lifecycle events are fired during various stages of navigation. They can be defined in any component type which is pushed/popped from a NavController”. However, the lifecycle event is also executed when going there by using setRoot… just saying… documentation needs to get better.