# Pop to a page before Tabs page IONIC2

**URL:** <https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105>\
**Category:** ionic-v3\
**Created:** [December 2, 2016, 6:54pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105 "2016-12-02T18:54:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaulGM](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/raulgm/32/144112_2.png) [@RaulGM](https://forum.ionicframework.com/u/RaulGM)\
**Post date:** [December 2, 2016, 6:54pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/1 "2016-12-02T18:54:45Z")

</div>

Hello, I’m having a navigation issue with my app and I can’t figure how to fix it. I’ve been looking for a solution in this forum with no luck. Here is the issue:

I have an app which has a log in. After you successfully log in, it redirects you to a tabs page.

My question is: how is it possible to get to the login page again?

When I hit logout, it, among other stuff should redirect you to the root page, `this.navCtrl.popToRoot ();`. My problem is that the tabs gets blank (the tabs doesn’t disappear) and I am no able to do any more stuff. I’d like this to redirect me to the login page. Any recommendations?

Thanks!

---

<div class="post-metadata">

**Author:** ![GabrielBarreto](https://avatars.discourse-cdn.com/v4/letter/g/4491bb/32.png) [@GabrielBarreto](https://forum.ionicframework.com/u/GabrielBarreto)\
**Post date:** [December 2, 2016, 7:25pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/2 "2016-12-02T19:25:25Z")

</div>

Could you post some code? Is your login page the root page of your app? Is it a normal page? A modal?

have you tried to set the login page as root again and then navigating to it? like:  
this.navCtrl.setRoot(LoginPage);  
this.navCtrl.push(LoginPage);

---

<div class="post-metadata">

**Author:** ![RaulGM](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/raulgm/32/144112_2.png) [@RaulGM](https://forum.ionicframework.com/u/RaulGM)\
**Post date:** [December 2, 2016, 7:34pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/3 "2016-12-02T19:34:31Z")

</div>

Login.ts:  
`this.navCtrl.push (Tabs);`

Tabs.ts  
`tab1Root: any = One; tab2Root: any = Two; tab3Root: any = Three;`

Tabs.html  
`<ion-tabs> <ion-tab [root] = "tab1Root" tabTitle = "one"></ion-tab> <ion-tab [root] = "tab2Root" tabTitle = "two"></ion-tab> <ion-tab [root] = "tab3Root" tabTitle = "three"></ion-tab> </ion-tabs>`

I don’t understand it very good. I’m setting those three tabs to the root page of each tab. But when I run the command `this.navCtrl.popToRoot ();` it turns blank.

---

<div class="post-metadata">

**Author:** ![piano\_bo](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@piano\_bo](https://forum.ionicframework.com/u/piano_bo)\
**Post date:** [January 9, 2017, 5:32pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/4 "2017-01-09T17:32:13Z")

</div>

Hi, I have exactly the same problem : did you find a solution?

I tried several combinations :

1. The following code does nothing.

> this.navCtrl.setRoot(LoginPage);  
> this.navCtrl.push(LoginPage);

1. This code makes the LoginPage appear BUT the Tabs remain (and it is possible to navigate to the other tabs)

> this.navCtrl.setRoot(LoginPage);  
> this.navCtrl.popToRoot();

1. This code does nothing

> this.navCtrl.setRoot(LoginPage);  
> this.navCtrl.pop(TabsPage);  
> this.navCtrl.popToRoot();

Please help me to find out if this is a bug of Ionic 2 or if there is a way to solve the problem.

---

<div class="post-metadata">

**Author:** ![RaulGM](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/raulgm/32/144112_2.png) [@RaulGM](https://forum.ionicframework.com/u/RaulGM)\
**Post date:** [January 9, 2017, 5:52pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/5 "2017-01-09T17:52:58Z")

</div>

Hahaha. Loved the third one.

I have found the solution.

```
import { App } from 'ionic-angular'; // add this library.

constructor (
  public app: App // initialize it.
) {}

logut () { // and in the function, 
  this.authServ.logout (); // this is a function to logout from the server
  const root = this.app.getRootNav (); // in this line, you have to declare a root, which is the app's root 
  root.popToRoot (); // here you go to the root.
}

```

Hope it works for you as well, if not, maybe I forgot something that I can’t remember now. Hope it does, thou.

Happy coding!

---

<div class="post-metadata">

**Author:** ![piano\_bo](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@piano\_bo](https://forum.ionicframework.com/u/piano_bo)\
**Post date:** [January 9, 2017, 6:11pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/6 "2017-01-09T18:11:54Z")

</div>

Thank you very much for you (quick) answer.  
But it still doesn’t work… I still see the Tabs.  
If you find another line of code… or if someone else has solved the problem…

---

<div class="post-metadata">

**Author:** ![RaulGM](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/raulgm/32/144112_2.png) [@RaulGM](https://forum.ionicframework.com/u/RaulGM)\
**Post date:** [January 9, 2017, 6:58pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/7 "2017-01-09T18:58:06Z")

</div>

It should work. I’ve seen my code and there’s no extra code besides that.

Could you share some of your work? Like how are you calling the tabs, your whole app.component, and everything you think that could help me in order to help you.

Do you have errors with my code? What is the behavior?

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [January 9, 2017, 8:25pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/8 "2017-01-09T20:25:16Z")

</div>

If you’re not wedded to using `pop`, here’s how I handle this situation. I have a service that exposes an authentication notifier which is a `ReplaySubject<boolean>` with a stack depth of 1. In the `platform.ready` stanza of the app component’s constructor, I subscribe to it and change the app’s root page like so:

```auto
authenticationNotifier.subscribe((authed) => {
  if (authed) {
    this.rootPage = AuthedPage;
   } else {
    this.rootPage = UnauthedPage;
   }
});

```

Now from anywhere else in the app, we can inject the service that provides the authentication notifier, and call `next(true)` on it to say “the user is now authenticated (they logged in successfully)” or `next(false)` to say “no longer authenticated (logged out, session timed out, whatever)”. Nobody has to mess around with NavControllers at all.

---

<div class="post-metadata">

**Author:** ![piano\_bo](https://avatars.discourse-cdn.com/v4/letter/p/3ab097/32.png) [@piano\_bo](https://forum.ionicframework.com/u/piano_bo)\
**Post date:** [January 10, 2017, 2:48pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/9 "2017-01-10T14:48:16Z")

</div>

@RaulGM  
I have to mention that I still use the beta 11 version (because the build is way faster). I suspect it comes from there. So I will freeze this problem for the moment and wait the migration to see if the problem persists.

@rapropos  
Thank you for your valuable advise. It could definitively be a way to solve this.

---

<div class="post-metadata">

**Author:** ![crzapata](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/crzapata/32/71673_2.png) [@crzapata](https://forum.ionicframework.com/u/crzapata)\
**Post date:** [January 11, 2017, 5:34pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/10 "2017-01-11T17:34:56Z")

</div>

@rapropos Thank you for this! I’ve been struggling with how to present a modal login form anytime a JWT is expired and your solution worked perfectly!

---

<div class="post-metadata">

**Author:** ![Luki\_wkn](https://avatars.discourse-cdn.com/v4/letter/l/e79b87/32.png) [@Luki\_wkn](https://forum.ionicframework.com/u/Luki_wkn)\
**Post date:** [May 12, 2017, 1:41pm UTC](https://forum.ionicframework.com/t/pop-to-a-page-before-tabs-page-ionic2/72105/11 "2017-05-12T13:41:51Z")

</div>

this.appCtrl.goBack(); worked for me
