Skip to content

Instantly share code, notes, and snippets.

@tomysmile
Created December 19, 2015 10:58
Show Gist options
  • Save tomysmile/b0c695f57998505a2c71 to your computer and use it in GitHub Desktop.
Save tomysmile/b0c695f57998505a2c71 to your computer and use it in GitHub Desktop.
ionic: change nav-back-button route
$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
   //assign the "from" or "to" parameter to something
console.log(from)
});

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

 if (from.name == "app.view2" && to.name =="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 (from.name == "app.view2" && to.name =="app.view1"){
        //do something
   }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment