this.navCtrl.getActive showing last page, not current?!


#1

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.


#2

So I really couldn’t get that to work… can anyone from the team please look into my logic?

Logic assumption (please check if this is foolish): I want to have a provider/service that communicates to all my pages/views where the user currently is on… so that I don’t have to do this check on every page… makes sense to me… however, to be able to CHECK which page I am on from within a provider, I need to import viewcontroller, or navcontroller etc. and use them… which I can’t… so what the…?!


#3

ionViewDidLoad and ionViewDidEnter are both giving me the previous page as well :frowning:


#4

bryandh, can you please describe what you are trying to do? Maybe my workaround works for you too


#5

Nothing really, I just tried if retrieving the component in the ionViewDidEnter event would solve your issue but it had the same outcome.

I’m actually not dealing with this issue. However, I am curious as to what your workaround is?