Detect Specific .state change


Is there any method to detect Particular states change only like in my case
I want to run a function only if we go from .state 1 to .state 2.

if(.state1 to .state2) {
I have searched too but found nothing related to this.


You could track history and read it on each route transition

$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
    console.log('Next route: ',; 
    console.log("Previous route: ", $ionicHistory.currentStateName());

The first one tell you which route are you trying to transition and the second the last route.


Thank you @gil13 for responding,
but I have got what I exactly need.

$rootScope.$on(’$stateChangeStart’, function(ev, toState, toParams, fromState, fromParams){
var states = [‘stateB’, ‘stateC’, ‘stateD’];
if( == ‘stateA’ && states.indexOf( > -1) {
// run your code