My Ionic 5 application has the following 3 pages with the navigation path
HomePage -> UserPage (with canDeactivate guard) -> SharePage
UserPage canDeactivate method:
canDeactivate() {
const alert = await this.alertCtrl.create({
message: 'Do you want to go back?',
buttons: [
{
text: 'No',
role: 'cancel',
handler: () => { }
},
{
text: 'Yes',
handler: () => { }
}
]
});
await alert.present();
let data = await alert.onDidDismiss();
if (data.role == 'cancel') {
return false;
} else {
return true;
}
}
In UserPage, on the back button when I choose 'Yes' it works fine and takes me back to HomePage.
- When I choose 'No', the canDeactivate method returns false and UserPage remains open.
- Then I click on the Share button to navigate to SharePage. The share page becomes the root page and it does not have the back button