registerBackButtonAction default action

How can I call the default action of the backButtonAction once I’ve registered my own action?

        this.platform.registerBackButtonAction(() => {

Which Ionic Version? 1.x or 2.x


Right now this is still pretty roughed out. We have not made this as expressive as it was in V1, but hope to do so post 2.0 final. So for now, I’d suggest not trying to override the default back button behavior.

Well, I have to. It exits the app even if the user is not in the mainscreen/page.
Is there some hacky way to do it?

Could you show me where the source to the function is so that I can just reproduce and modify it?

There is not hacky way to work around this. The source for it is not accessible from the outside.

I also require the ability to override the default action, but only for one page. I either need to de-register my callback when the page leaves, or I need to be able to call the default if I can see that I’m no longer on that page. I see no way to do either of these. Any suggestions?

1 Like

I am following the same goal, see SO.

I was confused reading the doc between ionic 1 and 2. In the doc for ionic 1, it lists the priorities:

The priorities for the existing back button hooks are as follows: Return to previous view = 100 Close side menu = 150 Dismiss modal = 200 Close action sheet = 300 Dismiss popup = 400 Dismiss loading overlay = 500

Are those rules of priorities still working in Ionic 2?

If this is the case, I have an idea to go around the problem. Let’s say on a specific page in ionViewWillEnter() I do:


Then on ionViewWillLeave():

this.platform.registerBackButtonAction({ Return to previous view = 100 },101);

The idea is to put back the function that does { Return to previous view } at the priority 101 to cancel the `this.platform.exitApp that had been set previously on priority 101.

The problem is that I don’t know how to call { Return to previous view = 100 }, any idea?

For my particular case: To close app on android back button when user is on one of the main Tab pages,

I’ve found a work around by emptying the Tabs._selectHistory array. See here for details.

It looks like there’s a solution to this:

Taken from: Android hardware back button in ionic

var unregister = this.platform.registerBackButtonAction(() => {

I have successfully tested it in my phone (Nexus 5).

by using navCtrl, getPrevious(view)?

@nylex, is your message a suggestion for me? In my case this issue has been closed with the solution that I’ve found.

let p: any = this.platform;