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?
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.
Any idea how to change that behavior? Note that in my app.component.ts, I’m setting the root page on launch.
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();
});
}
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: