title: Angular UI Router 1.0.0 - prevent route load with $transitions.onBefore
body: <p>I upgraded to UI Router 1.0.0, which has changed from <code>.$on($stateChangeX</code> to <code>$transitions.onX(</code> (<a href="https://ui-router.github.io/docs/latest/classes/transition.transition-1.html" rel="noreferrer">see $transitions here</a>).</p>
  
  <p>I need to resolve the user's profile and their access BEFORE navigation to the page (e.g. the user should never see the page they're attempting to transition to). Before, I was able to use a <code>resolve</code> directly in the <code>state</code> and pass thru things I need sequentially, as such:</p>
  
  <pre><code>state('my-state', {
          ...
          resolve : {
              ProfileLoaded : ['$rootScope', function ($rootScope) {
                  return $rootScope.loadProfile();
              }],
              access: ['Access', 'ProfileLoaded', function (Access, ProfileLoaded) {
                  return Access.hasORRoles(['admin']); //either $q.reject(status code); or "200"
              }]
          }
      })
  </code></pre>
  
  <p>Then I could easily retrieve the error type in <code>$stateChangeError</code>:</p>
  
  <pre><code>app.run(...
      $rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, error) {
  
         if (error === 401) {
             $state.go('home');
         }
         ...
  </code></pre>
  
  <hr>
  
  <p>With <code>$transitions</code>, I'm trying to do the same thing...</p>
  
  <pre><code>.state('user.my-page', {
    ...
    data: {
      loadProfile: true,
      roles: [
        'admin'
      ]
    }
  });
  
  
  app.run(...
  
    $transitions.onBefore({to: profile}, function(trans) {
      return loadProfile().then(function (prof) {
        var substate = trans.to();
        return Access.hasORRoles(substate.data.roles); //either $q.reject(status code); or "200"
      });
    });
  
    $transitions.onError({}, function(trans) {
      var error = trans &amp;&amp; trans._error;
  
      if (error == 401) {
        $state.go('home');
      }
      ...
  </code></pre>
  
  <p><strong>So my question is:</strong></p>
  
  <p>Does <code>onBefore</code> do the same thing as <code>resolve</code> in terms of ensuring the user can't navigate before data is checked? The page is still loading and THEN redirecting with <code>$state.go</code> after the page loads.</p>