I recently developed a chat application that redirects users to a tabs page upon login.
<ion-tabs tabsPlacement="top" color="header" tabsHighlight=true>
<ion-tab [root]="tab1" tabTitle="Chats" tabIcon="chatbubbles"></ion-tab>
<ion-tab [root]="tab2" tabTitle="Groups" tabIcon="contacts"></ion-tab>
<ion-tab [root]="tab3" tabTitle="Profile" tabIcon="contact"></ion-tab>
</ion-tabs>
https://i.sstatic.net/k8tRk.png
After logging in, I tried to retrieve the active page from the tabs using
. However, it returnsconsole.log(this.navCtrl.getActive().name);
undefined
. Can someone explain why?When I navigate to a new page by clicking the app icon on the header with
, the current active page displays the previous page name "this.navCtrl.push('FriendsPage');
ChatPage
" instead of "FriendsPage
" https://i.sstatic.net/nWG38.png
Edit: Added backbutton action
this.platform.registerBackButtonAction(() => {
let activePortal = this.ionicApp._loadingPortal.getActive() ||
this.ionicApp._modalPortal.getActive() ||
this.ionicApp._toastPortal.getActive() ||
this.ionicApp._overlayPortal.getActive();
if (activePortal) {
activePortal.dismiss();
} else {
if (this.nav.canGoBack()) {
this.nav.pop();
} else {
if (this.nav.getActive().name === "LoginPage"||this.nav.getActive().name === "SignupPage") {
this.platform.exitApp();
}else {
this.generic.showAlertConfirm("Exit", "Do you want to exit the app?", this.onYesHandler, this.onNoHandler, "backPress");
}
}
}
})
In my scenario, when a user goes to the FriendsPage from the tabs and presses the hardware back button, an alert message pops up instead of the view simply popping as expected.
this.generic.showAlertConfirm("Exit", "Do you want to exit the app?", this.onYesHandler, this.onNoHandler, "backPress");
I would appreciate any assistance in resolving this issue.
Warm Regards,
Anand Raj