Prevent leaving from page [RESOLVED]

Is there an easy way to prevent page popping when pressing back? This is needed becuase I need to show confirmation dialog to user.

I’ve seen this, but this doesn’t work.

ionViewWillLeave() {
return false;
}

I’ve now implemented this by replacing hardware back button action and visual back button with my own, but this is not very pretty solution. I started now using split pane and this problem is really annoying.

EDIT.
Well this is awkward. Just after this I found the solution.

ionViewCanLeave() {
    return new Promise((resolve, reject) => {
        let confirm = this.alertCtrl.create({
            message: 'Leave the page ?',
            buttons: [
                {
                text: 'Yes',
                handler: () => {
                  resolve();
                }
                },
                {
                text: 'No',
                handler: () => {
                  reject();
                }
              }
            ]
            });
        confirm.present();
    });
  }
1 Like