ui-router: Deprecated events and hooks

If you are using latest version of ui-router (now it’s 1.0.0-alpha) you probably already noticed that there are no events that we all got used to: $stateChangeCancel,  $stateChangeError, $stateChangeStart$stateChangeSuccess$stateNotFound. All of them are deprecated in 1.0.0-alpha.3 and you can not use them anymore in 1.0.0-alpha.5.

If you want to move to new version of ui-router you should make such changes:

$stateChangeCancel

It was an event that was thrown when somebody called “event.preventDefault()”. Now everything is controlled by transitions so no chance to get such event.

$stateChangeError

old code

$rootScope.$on('$stateChangeError', function(event, toState) {
    //some code to handle the error
})

new code

$transitions.onError({ to: 'stateName' }, function($error$) {
  console.log($error$);
}

in progress

$stateChangeStart

old code

$rootScope.$on('$stateChangeStart', function(event, toState) {
    event.preventDefault();
})

new code

$transitions.onEnter({ to: 'stateName' }, function($state$, $transition$) {
  return $q.reject()
}

$stateChangeSuccess

old code

$rootScope.$on('$stateChangeSuccess', function(event) {})

new code

$transitions.onSuccess({}, () => {});

$stateNotFound

old code

$rootScope.$on('$stateNotFound', function(event) {})

new code

$stateProvider.onInvalid(($to$, $from$) => {})

 

Sandbox to play with all examples.