How to set the root nav the right way?


#1

Hi,

Can someone tell me the difference between these 2 lines?

this.appCtrl.getRootNav().push(loginPage);
this.navCtrl.setRoot(loginPage);

The scenario here is the user is no longer authenticated and I want to direct them to the login page of my app. I am using tabs so I don’t want the tabs to show when the user gets navigated to the loginPage.

I have looked at some forums but it’s not directly clear to me on which method I should use.

Thanks in advance.


#2

The first one is terrible no matter where you are. The second one might make sense, but only if it’s in the app component. I would still prefer assigning to a rootPage property in most cases.


#3

My rootPage = TabsComponent with a default hometab selected. Then depending on an API call it sees if the user is authenticated or not, directing them to the loginPage.


#4

That’s a very common situation, and here is how I handle it with no direct interaction with NavControllers at all.