Changing the back-button "url" / "back state"


I have view that I get to him after a wizard.
I want the back button to take directly to home view.
I saw the solution to point to the previous-previous, How to manipulate a back button pointer to point to a previous-previous View.
But, In my case I have multiple steps in creation process, so the above solution will destory the back at each step.

So, one solution is to use hide-back-button="true" and add left button with "ui-sref=home". But this solution removes the back button animation that creates the very important native feel.

Is there a way to set the back-button “back state” kind of state.go("home") ...

How to use $windows.history.back

Look at this sample for going to specific states.

In particular this code:’

    // This will show you the history stuff.
    var history = $ionicViewService.getBackView();

The back-button itself doesn’t have an API that allows you to tell it where to go.


This works pretty well:

$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
   //assign the "from" or "to" parameter to something

Pretty much you can see as the page you are going to; and as the state you are coming from.

 if ( == "app.view2" && =="app.view1"){
     // do something when you go from state app.view2 to state app.view1

Full code:

$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
   if ( == "app.view2" && =="app.view1"){
        //do something

Courtesy of: