title: Angular ui router - Redirection doesn't work at all
body: <p>I'm using <code>ui.router</code> for routing in my Angular app. There is a typical login scenario, where I'm redirecting a user to the login url if he's not logged in. Without the ui.router library, this worked fine using $routeChangeStart event combined with <code>$location.path</code>. Now, I'm using the <code>$stateChangeStart</code> event, combined with <code>$state.go</code>, and the nothing works! It also sends my browser into an infinite loop. I read from other sources that this is a known bug, and none of the suggested solutions work for me. Moreover, <code>$location.path</code> too doesn't redirect to the login page.</p>
  
  <p>This is how I've configured my paths:</p>
  
  <pre><code> .config(['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) {
      $stateProvider
          .state('main', {
              url: '/',
              templateUrl: 'views/main.html',
              controller: 'MainCtrl'
          })
          .state('about', {
              url: '/about',
              templateUrl: 'views/about.html',
              controller: 'AboutCtrl'
          })
          .state('login', {
              url: '/login',
              templateUrl: 'views/loginform.html',
              controller: 'LoginCtrl'
          });
      $urlRouterProvider.otherwise("/");
  }])
  </code></pre>
  
  <p>And my <code>run</code> method:</p>
  
  <pre><code>.run(['$state', '$rootScope', '$location', function($state, $rootScope, $location) {
      //Check when routing starts
      //event, next, current
      $rootScope.$on( '$stateChangeStart', function(e, toState, toParams, fromState, fromParams) {
          //Redirect to login if the user is not logged in
          if (!isUserLoggedIn) {
  
              //Some suggestion
              //e.preventDefault();
              console.log('Not logged in');
  
              //Infinite loop, kills my browser!
              $state.go('login');
              $state.transitionTo('login');
  
              //Some suggestion
              $state.go('login', { url: '/login'});
  
              //Doesn't work
              $location.path('/login');
  
              //$location.path( $state.href('login');
              console.log('Redirected');
          }
      });
  </code></pre>