# Go back to the root page

**URL:** <https://forum.ionicframework.com/t/go-back-to-the-root-page/49861>\
**Category:** ionic-v3\
**Created:** [April 20, 2016, 11:11am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861 "2016-04-20T11:11:57Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidla](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/davidla/32/109812_2.png) [@davidla](https://forum.ionicframework.com/u/davidla)\
**Post date:** [April 20, 2016, 11:11am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/1 "2016-04-20T11:11:58Z")

</div>

Hi ,  
i’m using NavController and i need to go back to the root page of my navigation.  
Example:

I have TabsPage -\> Page1-\>Page2.  
now in Page2 i need to create a button, that brings me back to the root page (TabsPage) .  
but when i type “this.nav.pop()” it’s redirect back to Page1.  
Please any suggestions?

---

<div class="post-metadata">

**Author:** ![snikh](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/snikh/32/101385_2.png) [@snikh](https://forum.ionicframework.com/u/snikh)\
**Post date:** [April 20, 2016, 11:15am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/2 "2016-04-20T11:15:50Z")

</div>

Try this:

this.nav.setRoot(TabsPage);

---

<div class="post-metadata">

**Author:** ![davidla](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/davidla/32/109812_2.png) [@davidla](https://forum.ionicframework.com/u/davidla)\
**Post date:** [April 20, 2016, 11:20am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/3 "2016-04-20T11:20:17Z")

</div>

> [@snikh](#):
>
> this.nav.setRoot(TabsPage);

Nothing happens 😥

---

<div class="post-metadata">

**Author:** ![El\_Dee565](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/el_dee565/32/99956_2.png) [@El\_Dee565](https://forum.ionicframework.com/u/El_Dee565)\
**Post date:** [April 20, 2016, 11:24am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/4 "2016-04-20T11:24:09Z")

</div>

Try this.nav.popToRoot() or this.nav.rootNav.setRoot(Tabs)

---

<div class="post-metadata">

**Author:** ![davidla](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/davidla/32/109812_2.png) [@davidla](https://forum.ionicframework.com/u/davidla)\
**Post date:** [April 20, 2016, 11:27am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/5 "2016-04-20T11:27:01Z")

</div>

> [@El\_Dee565](#):
>
> nav.popToRoot()

nav.popToRoot() works like a charm 🙂 thanks !

---

<div class="post-metadata">

**Author:** ![iofirag](https://avatars.discourse-cdn.com/v4/letter/i/a6a055/32.png) [@iofirag](https://forum.ionicframework.com/u/iofirag)\
**Post date:** [March 28, 2017, 9:38pm UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/7 "2017-03-28T21:38:52Z")

</div>

`this.nav.setRoot(TabsPage);`  
This line will not work lonely because you actually change the root, but the pages that still in the quoue stack is still there, and avoid you to see your root page changes

so you need to add the line:  
`this.nav.popToRoot()`  
tell the nav to drop all the views pushed to the quoue all the way to the root.

so in shortly:

> this.nav.setRoot(TabsPage);  
> this.nav.popToRoot();

---

<div class="post-metadata">

**Author:** ![Synnys](https://avatars.discourse-cdn.com/v4/letter/s/8797f3/32.png) [@Synnys](https://forum.ionicframework.com/u/Synnys)\
**Post date:** [May 11, 2017, 5:30pm UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/8 "2017-05-11T17:30:15Z")

</div>

Thanks you so muchhhhhhhhh!  
You save my life.😄

---

<div class="post-metadata">

**Author:** ![mraible](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@mraible](https://forum.ionicframework.com/u/mraible)\
**Post date:** [June 7, 2017, 8:05pm UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/9 "2017-06-07T20:05:27Z")

</div>

I tried this exact code in my `home.ts` and it works, but the tab icons are still on the bottom of the screen when it goes to login page.

```auto
logout() {
  this.oauthService.logOut();
  this.nav.setRoot(LoginPage);
  this.nav.popToRoot();
}

```

Any idea how to change that behavior? Note that in my `app.component.ts`, I’m setting the root page on launch.

```auto
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen,
            oauthService: OAuthService) {
  if (oauthService.hasValidIdToken()) {
    this.rootPage = TabsPage;
  } else {
    this.rootPage = LoginPage;
  }
  
  platform.ready().then(() => {
    // Okay, so the platform is ready and our plugins are available.
    // Here you can do any higher level native things you might need.
    statusBar.styleDefault();
    splashScreen.hide();
  });
}

```

---

<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:** [June 7, 2017, 9:45pm UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/10 "2017-06-07T21:45:53Z")

</div>

I prefer designing things so that the state of authentication is exposed as a `ReplaySubject` with a depth of 1. That way `logout()` does not have to ever interact with the navigation system at all. It just calls `next(false)` on the authentication state subject and lets the code you already have in the app component handle everything:

```auto
authService.notifier.subscribe((authed) => {
  if (authed) {
    this.rootPage = TabsPage;
  } else {
    this.rootPage = LoginPage;
  }
});

```

---

<div class="post-metadata">

**Author:** ![mmayori](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mmayori/32/90827_2.png) [@mmayori](https://forum.ionicframework.com/u/mmayori)\
**Post date:** [October 27, 2017, 3:02pm UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/11 "2017-10-27T15:02:15Z")

</div>

Works thanks …

---

<div class="post-metadata">

**Author:** ![rajkanase](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rajkanase/32/117784_2.png) [@rajkanase](https://forum.ionicframework.com/u/rajkanase)\
**Post date:** [March 19, 2018, 10:24am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/12 "2018-03-19T10:24:33Z")

</div>

@mraible  
Facing same problem !  
Have you solved this???

---

<div class="post-metadata">

**Author:** ![mraible](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@mraible](https://forum.ionicframework.com/u/mraible)\
**Post date:** [March 19, 2018, 3:19pm UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/13 "2018-03-19T15:19:59Z")

</div>

Yes, I was able to solve it using the following code:

```auto
constructor(public app: App, public oauthService: OAuthService) {
}

logout() {
  this.oauthService.logOut(true);
  this.app.getRootNavs()[0].setRoot(LoginPage);
}

```

---

<div class="post-metadata">

**Author:** ![Shaileshbappanadu](https://avatars.discourse-cdn.com/v4/letter/s/49beb7/32.png) [@Shaileshbappanadu](https://forum.ionicframework.com/u/Shaileshbappanadu)\
**Post date:** [June 5, 2018, 9:44am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/14 "2018-06-05T09:44:54Z")

</div>

Can you please provide the answer for this…I have raised the same question in this [How to skip TabsComponent Page, when user clicks Back button(\<) in Other page](https://forum.ionicframework.com/t/how-to-skip-tabscomponent-page-when-user-clicks-back-button-in-other-page/132149).

---

<div class="post-metadata">

**Author:** ![Avinashjagtap](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/avinashjagtap/32/122231_2.png) [@Avinashjagtap](https://forum.ionicframework.com/u/Avinashjagtap)\
**Post date:** [November 18, 2018, 8:01am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/15 "2018-11-18T08:01:07Z")

</div>

this.navCtrl.setRoot(HomePage)  
this.navCtrl.popToRoot();

---

<div class="post-metadata">

**Author:** ![adimaryadi](https://avatars.discourse-cdn.com/v4/letter/a/91b2a8/32.png) [@adimaryadi](https://forum.ionicframework.com/u/adimaryadi)\
**Post date:** [January 2, 2019, 5:01am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/16 "2019-01-02T05:01:58Z")

</div>

wooo work for me this.nav.popToRoot()

---

<div class="post-metadata">

**Author:** ![Gesti](https://avatars.discourse-cdn.com/v4/letter/g/3da27b/32.png) [@Gesti](https://forum.ionicframework.com/u/Gesti)\
**Post date:** [April 5, 2019, 6:41am UTC](https://forum.ionicframework.com/t/go-back-to-the-root-page/49861/17 "2019-04-05T06:41:44Z")

</div>

He asked how to go back to the root, not how to set another root.

The this.nav.popToRoot() is the right answer.
