title: Ui-Router $state.go inside $on('$stateChangeStart') is cauzing an infinite loop
body: <p>I'm trying to introduce login into the way the user navigates accross the application.</p>
  
  <p>I pretend to redirect the user to the page were he was before he navigate to the login page if that page meets specific requirements</p>
  
  <p>Preventing the event from the $stateChangeStart stop's the state change like expected but when i run the $state.go('into_somewhere') i enter an infinit loop</p>
  
  <p>My angular version is 1.3.1 and the ui-router is the latest</p>
  
  <pre><code>.factory('RouteHistory', function ($rootScope,$log, $state, Auth, $urlRouter, $timeout) {
  
      // after the user enter a page
      var currentState = '';
  
      // when the user is trying to access a page that he has not permissions
      // or that requires the user to be logged in
      var pendingState = '';
  
      var isMenuTogglerVisible = false;
      var skipFromStateVal = true;
  
      $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){
  
        event.preventDefault();
  
  
  
        if (toState.name == 'login' &amp;&amp; fromState.name != 'login'){
          $log.log('Ui-router: changing to login');
          // $urlRouter.sync();
          $state.go('login')
          //pendingState = fromState;
          //$log.log('Peding state updated to:' + pendingState.name );
          //$urlRouter.sync();
        }
  
        if (fromState.name == 'login' &amp;&amp; Auth.isLoggedIn()) {
          $log.log('Ui-router: going from login');
          //$state.go(fromState.name);
          $timeout(function(){
            // $state.go('home', null, {/*reload: true, location: 'replace'*/});
            $state.go('browse-machine');
            //$urlRouter.sync();
          },2000)
        }
  
  
  
        $log.log({
          'toState': toState,
          'toParams': toParams,
          'fromState': fromState,
          'fromParams': fromParams
        })
  
      })
  
  
      return {
  
      };
    });
  </code></pre>