I am quite new to Ionic and I struggle to go back to the previous page. Error Uncaught (in promise): navigation stack needs at least one root. However in login(), I push the TabsPage above the root (LoginPage). With pop() I would like to go back to LoginPage.
I would be glad if you could help.
Here is my code:
myApp.ts:
export class MyApp {
rootPage:any = 'LoginPage';
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {
platform.ready().then(() => {
statusBar.styleDefault();
splashScreen.hide();
});
}
}
login.ts:
public login() {
this.showLoading()
this.auth.login(this.registerCredentials).subscribe(allowed => {
if (allowed) {
this.nav.push(TabsPage);
} else {
this.showError("Email ou mot de passe incorrect");
}
},
error => {
this.showError(error);
});
}
tabs:
export class TabsPage {
tab1Root = OrdersPage;
tab2Root = AboutPage;
tab3Root = ProfilePage;
/**
* @constructor
*/
constructor(private navCtrl: NavController) {}
}
profile.ts:
public logout(){
this.auth.logout().subscribe(logedout => {
if(logedout){
this.navCtrl.pop();
}
});
}
Thank you.
TabsPagebut I don't see the code for it. - Kewin Doussetab3Root = ProfilePage;. Does that mean you then set the root toProfile? If yes, then it's the reason why you can't go back usingpop: Profile is now the root. - Kewin Dousse