# Confirm on back button press

**URL:** <https://forum.ionicframework.com/t/confirm-on-back-button-press/119898>\
**Category:** ionic-v3\
**Created:** [January 30, 2018, 3:10pm UTC](https://forum.ionicframework.com/t/confirm-on-back-button-press/119898 "2018-01-30T15:10:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nvirth](https://avatars.discourse-cdn.com/v4/letter/n/b2d939/32.png) [@nvirth](https://forum.ionicframework.com/u/nvirth)\
**Post date:** [January 30, 2018, 3:10pm UTC](https://forum.ionicframework.com/t/confirm-on-back-button-press/119898/1 "2018-01-30T15:10:27Z")

</div>

I would like to be able to cancel the backButtonPress event, but I don’t want to change its core behavior.

So, when the user is on specific pages, where poping the page would make the user lose its work, I would like to show the user a confirm message, like “if you leave now, all your work will be lost. [Leave] [Cancel]”.

I’ve found no solution for this here: [registerBackButtonAction default action](https://forum.ionicframework.com/t/registerbackbuttonaction-default-action/59445/6)

How could I do this in ionic 3?

---

<div class="post-metadata">

**Author:** ![mich356c](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mich356c/32/105794_2.png) [@mich356c](https://forum.ionicframework.com/u/mich356c)\
**Post date:** [January 30, 2018, 3:19pm UTC](https://forum.ionicframework.com/t/confirm-on-back-button-press/119898/2 "2018-01-30T15:19:00Z")

</div>

[https://ionicframework.com/docs/api/navigation/NavController/](https://ionicframework.com/docs/api/navigation/NavController/) and go down to “Lifecycle events”, I think `ionViewCanLeave` is what you’re looking for.

```auto
ionViewCanLeave() {
    return new Promise((resolve, reject) => {
        this.alertCtrl.create({
            enableBackdropDismiss: false,
            /* title and message etc ... */
            buttons: [{
                text: "Leave",
                handler: resolve
            },{
                text: "Stay",
                handler: reject
            }]
        }).present();
    });
}

```

Something along those lines

---

<div class="post-metadata">

**Author:** ![nvirth](https://avatars.discourse-cdn.com/v4/letter/n/b2d939/32.png) [@nvirth](https://forum.ionicframework.com/u/nvirth)\
**Post date:** [January 30, 2018, 7:33pm UTC](https://forum.ionicframework.com/t/confirm-on-back-button-press/119898/3 "2018-01-30T19:33:27Z")

</div>

Thank you, this worked like a charm! 🙂

---

<div class="post-metadata">

**Author:** ![nvirth](https://avatars.discourse-cdn.com/v4/letter/n/b2d939/32.png) [@nvirth](https://forum.ionicframework.com/u/nvirth)\
**Post date:** [February 15, 2018, 6:42pm UTC](https://forum.ionicframework.com/t/confirm-on-back-button-press/119898/4 "2018-02-15T18:42:01Z")

</div>

Actually, later it turned out it does work - but not like a charm 🙂  
It has conflict with SwipeBack, so in case a new reader needs this functionality, and also has to support SwipeBack, a workaround is needed.  
The issue:

> <https://github.com/ionic-team/ionic/issues/10415>

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:52pm UTC](https://forum.ionicframework.com/t/confirm-on-back-button-press/119898/5 "2021-07-19T21:52:48Z")

</div>

Closed on July 19, 2021, 9:52pm UTC


