title: ui-router onEnter "TypeError: Cannot read property 'globals' of null"
body: <p>I am using the <code>onEnter</code> property of ui-router state to redirect to a different state depending upon the user-type.</p>
  
  <p>The problem is that it gives <code>TypeError: Cannot read property 'globals' of null at $state.transition.resolved.then.$state.transition</code> when the 'dashboard' state (the one with the onEnter) is used in a <code>ui-sref</code> (the same error is thown if <code>ng-click</code> with $state.go('dashboard') is used.</p>
  
  <p>I also created a very simple example, without resolve, showing this problem </p>
  
  <p><a href="http://jsfiddle.net/klode/v6znebs5/" rel="nofollow">js-fiddle DEMO</a>. </p>
  
  <p>Am I missing something?</p>
  
  <p>in template</p>
  
  <pre><code>&lt;a href="" ui-sref="dashboard"&gt;DASHBOARD&lt;/a&gt;
  </code></pre>
  
  <p>in the config</p>
  
  <pre><code>    $urlRouterProvider.otherwise('/');
      $stateProvider
          .state('root', {
              url: '',
              abstract: true,
              resolve: {
                  user: function(authService) {
                      return authService.requestUser();
                  }
              },
              views: {
                  'footer@': {
                      templateUrl: 'views/footer.html',
                  }
              }
          })
          .state('dashboard', {
              parent: 'root',
              url: '/',
              onEnter: ['$state', 'authService', function($state, authService){
                  console.log ('redirectTo');
                  if (authService.isStudent()) {
                      $state.go('student');
                  }
                  if (authService.isTeacher()) {
                      $state.go('teacher');
                  }
              }]
          })
          .state('student', {
              parent: 'root',
              url: '/student',
              views: {
                  'header@': {
                      templateUrl: 'views/student/studentHeader.html',
                      controller: 'StudentHeaderCtrl'
                  },
                  'content@': {
                      templateUrl: 'views/student/student.html',
                      controller: 'StudentCtrl'
                  },
              },
          })
  </code></pre>
  
  <p><strong>Answer by Thinley Koblensky</strong>: </p>
  
  <p>The problem is caused by using the onEnter property on the dashboard state together with $state.go() and ui-sref</p>
  
  <p>As a workaround: </p>
  
  <ol>
  <li>use $location.path() in the onEnter property function </li>
  <li>and use <code>ng-href=“/“</code> or <code>$location.path(‘/‘)</code> to navigate to the ‘dashboard’ state </li>
  </ol>