registerBackButtonAction in a controller blocks the back button in whole app


I have used registerBackButtonAction in one controller, so it should be called just in that view using that controller.
But it happens that the back button is like disabled and to make it work i should implement the behavior in each controller related to a view.
Also i would like to link a animation like “nav-direction=back” used in a view, is it possible?


You can put the registerBackButtonAction in the app’s run function and then check the state that you are in to only override it on that state:$ionicPlatform, $state) {
    $ionicPlatform.registerBackButtonAction(function () {
        if ($ == "stateToOverride") {
            // override the back button for this state
        // Clear the history before navigating back since these are top level menu items
        } else {
    }, 100);

I don’t understand your second question. Can you explain what you mean?

1 Like

I was thinking to put it in the app’s run function, mine was more an idea to put it into the controller to see if it works just in that case :).

I try to explain better my other question:
When i click the back button in a device the view comes from left to right instead of from right to left, so i would like to control this animation, i hope i explained myself

Also i have another doubt:
I have this navigation path with different states:
A -> B -> C -> D
When i press the back button on my device works fine going back forward:
A <- B <- C <- D
but when i am in the state D, i have a ng-click that calls a service and then i call the history back:

<i nav-direction="back" ng-click="insert()"  class="button button-small icon icon-paper-plane pull-right"></i>

in My controller:

$scope.insert = function(){


Following this path it happens:
So from D goes to C and then back to D.
I hope its clear :smiley:

You can add $ionicViewSwitcher.nextDirection('forward'); right before you call $ionicHistory.goBack().

Am I understanding correctly? :smile:

that is the solution!
But :smiley: now i have another weird behavior:
I have used one code pen and changed a bit:
From the home you go to page B then page C, then go back to page B and then again to page C, in this moment if i decide to go back with the back button of my device it goes to page B then C then B again and finally A, the behavior that i expect is that should go directly to A


Try using $ionicHistory.goBack() instead of

I don’t know if this will work, but it sounds good in theory.

Yes i have tried that but i get still the same behavior :slight_smile:

i have found the solution on this topic:

1 Like

This solved an issue I had! thank you so much :slight_smile: