1

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.

  1. When I choose 'No', the canDeactivate method returns false and UserPage remains open.
  2. 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
Tapas Mukherjee
  • 2,088
  • 1
  • 27
  • 66

0 Answers0