Ionic 4 | Overridden Back Press Event and Show Exit Confirm on Application Close

We have already discussed How to Override Back Press Event in Ionic’s V3 which we can easily do by using Platform’s registerBackButtonAction method. But in Ionic’s V4 version this method simply does not work.

So in this post, we will create an Ionic V4 Application to demonstrate overriding of Back Press Event in Ionic 4 Application. We will also discuss how to get the current Component name to handle it more conveniently.

Let’s create an Ionic 4 Application first using following CLI command as Ionic 4 is still in beta phase.

In Ionic 4 Application we use Platform’s backButton Interface as follows

Here 999990 is the priority, we need to give this number due to some ongoing bugs in library 😛

Implement Back Press Event in any specific Component

Open file then replace the following code

Here priority is 999999 which should be greater then app.component.ts event priority.

In ionViewWillLeave event will unsubscribe BackButton event when app moves to any other view/ page.


Thanks for visiting :) Let me know if you have some suggestions or feedback for this post in the comment section. Looking for any tutorial or demo on FreakyJolly, just drop me a message here

Leave a Reply

2 Comment threads
0 Thread replies
Most reacted comment
Hottest comment thread
2 Comment authors
stevecode android example Recent comment authors
newest oldest most voted
Notify of
code android example

i think code this add event when click


I used this code but when I put in ionViewWillLeave I get an error message saying this.unsubscribeBackEvent is not a function. Please let me know what it is that I am doing wrong. Everything else is working just as I would like it except this function.