# (Ionic 5) Override ion-back-button logic to show confirm message before leaving a page

**URL:** <https://forum.ionicframework.com/t/ionic-5-override-ion-back-button-logic-to-show-confirm-message-before-leaving-a-page/191722>\
**Category:** Ionic Framework\
**Created:** [June 24, 2020, 8:58am UTC](https://forum.ionicframework.com/t/ionic-5-override-ion-back-button-logic-to-show-confirm-message-before-leaving-a-page/191722 "2020-06-24T08:58:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![olaisen](https://avatars.discourse-cdn.com/v4/letter/o/c37758/32.png) [@olaisen](https://forum.ionicframework.com/u/olaisen)\
**Post date:** [June 24, 2020, 8:58am UTC](https://forum.ionicframework.com/t/ionic-5-override-ion-back-button-logic-to-show-confirm-message-before-leaving-a-page/191722/1 "2020-06-24T08:58:43Z")

</div>

Hi guys! Is there an easy way to prevent page popping when pressing ion back button? I’d like to show a confirmation dialog to user before leaving page. I’m using Ionic 5.2.2 and trying this, but not working:

**component.html**  
\<ion-back-button \*ngIf=“canGoBack” (click)=“this.backButtonClicked($event)”\>

**component.ts**  
public backButtonClicked(event) {

```
event.preventDefault();

event.stopPropagation();

event.stopImmediatePropagation(); 

```

}

---

<div class="post-metadata">

**Author:** ![olaisen](https://avatars.discourse-cdn.com/v4/letter/o/c37758/32.png) [@olaisen](https://forum.ionicframework.com/u/olaisen)\
**Post date:** [July 31, 2020, 2:07pm UTC](https://forum.ionicframework.com/t/ionic-5-override-ion-back-button-logic-to-show-confirm-message-before-leaving-a-page/191722/2 "2020-07-31T14:07:16Z")

</div>

Up! Nobody have this problem? Very strange for me…

---

<div class="post-metadata">

**Author:** ![EinfachHans](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/einfachhans/32/130917_2.png) [@EinfachHans](https://forum.ionicframework.com/u/EinfachHans)\
**Post date:** [July 31, 2020, 2:12pm UTC](https://forum.ionicframework.com/t/ionic-5-override-ion-back-button-logic-to-show-confirm-message-before-leaving-a-page/191722/3 "2020-07-31T14:12:01Z")

</div>

I would solve it by using the Angular’s **CanDeactivate Guard**. I found this Tutorial after googling: [https://www.concretepage.com/angular-2/angular-candeactivate-guard-example](https://www.concretepage.com/angular-2/angular-candeactivate-guard-example) . Try it out, if you have questions, ping me 😊

---

<div class="post-metadata">

**Author:** ![olaisen](https://avatars.discourse-cdn.com/v4/letter/o/c37758/32.png) [@olaisen](https://forum.ionicframework.com/u/olaisen)\
**Post date:** [August 3, 2020, 9:02am UTC](https://forum.ionicframework.com/t/ionic-5-override-ion-back-button-logic-to-show-confirm-message-before-leaving-a-page/191722/4 "2020-08-03T09:02:45Z")

</div>

Thank you so much. I didn’t think about CanDeactivateGuard that is specific for my scope 🙂
