Set root without tabs

I have the normal workflow of an app with login: First page is the login screen and you get to the tabs page after login. Now I’m trying to implement a logout button. But if I use


the tabbar is still displayed.
I also tried to use

@ViewChild(‘myNav’) nav: NavController

which turns out to be undefined.

Any advice how to make a logout with goes back to Login without the tabbar?

I created a minimum example if someone wants to try it himself. I’m happy to send the src folder if needed :slight_smile:


Exactly de same case here, with the same use case.

The tab bar still showing after:



I report a bug about that yesterday and it turns out it is not :wink:

To set a full new root outside the tabs, do something like:;

@manucorporat explained this:

You are changing the root of the tab, remember that each tab has his own navigation stack. You have to setRoot() to the root navigation controller:


I think you are going about this backwards. It feels much more natural to me to do this reactively instead of declaratively, by having an observable in a service somewhere that tracks the authentication state of the user. To log out, inject that service and call its logout function. In the application component or some root page, also inject the same service, subscribe to it, and change root pages there.

1 Like

Amazing! Thank you! @reedrichards

BTW, I did with subscribe

At some page:

   logout() {'user:logout');

In a centralized place:'user:logout', () => {;

Thx for the centralized code example, looks coolio!


Using an Observable makes this a bit easier:

@Component({ template: "<ion-nav [root]='rootPage'></ion-nav>" }) export class MyApp { public rootPage: any; constructor( public platform: Platform, public sessionSvc: SessionService ) { platform.ready().then(() => { // observe login state and route accordingly this.sessionSvc.isLoggedIn.subscribe(isLoggedIn => { if ( isLoggedIn ) { this.rootPage = TabsPage; } else { this.rootPage = LoginPage; } // end if }); }); } }
then some logout method:

public logout(): void {; }

How did you manage to get an instance of app ( ?


constructor(private app:App) {}

Tnx @reedrichards.

Do I need to import anything? If I just add this parameter to constructor I get an error:

Can't find name App

import { App } from ‘ionic-angular’;


Thanks Guys! It works great now!

1 Like

Yes, this solution works; but it breaks the path to images on all views when running on devices or emulators.

I really like the kind of approach you are suggesting @rapropos, about having some service handling changes in the root page, but I’m pretty new to the Ionic framework and really don’t have much clue about doing what you proppose in your answer.

Could you give me some advice or point me to some documentation where this is explained in more detail?

NavController also works for me to set the root page. Importing and Injecting App is not required anymore.