title: Angular UI router how can I redirect a deep link?
body: <p>I am new to Angular UI router and am trying to understand how I can prevent users from using a saved hyperlink to jump into the middle of my app. I always want all favorites or otherwise memorized links to be forced to run the code runs when they initially come to the site. However, I don't want to prevent the user from reaching the state if they get to it via the apps menus and tabs.</p>
  
  <p>Code-wise what I want to do is force a link to "/feature1/subfeature1" to "/" in the state tree below, but only if the link is from some link the user memorized.</p>
  
  <pre><code>$stateProvider
  .state('main', {
    url: "/",
    templateUrl: "partials/main.html"
  })
  .state('feature1', {
    url: "/feature1",
    templateUrl: "partials/feature1.html"
  })
  .state('feature1.subfeature1', {
    url: "/feature1/subfeature1",
    templateUrl: "partials/feature1.subfeature1.html",
    controller: ......
    }
  })
  </code></pre>
  
  <p>The Angular UI Router FAQ had section on preventing a user from reaching a state, but when I ran a sample the event handler is invoked for all stateChangeStart events, including legitimate navigation within the app via $state.go(). I was hoping to differentiate between detect hyperlinks that jump into the middle of the app and $state.go(), since I only use $state.go() to navigate states.  Code-wise I think want to do something like the code below.  But, don't know what code goes into the "NEED TEST HERE".</p>
  
  <pre><code> app.run(function($rootScope, $state,) {
     $rootScope.$on('$stateChangeStart', function(e, to) {
  
      var isDeepLink =  NEED TEST HERE 
  
      if (isDeepLink ) {
        e.preventDefault();
      // Optionally set option.notify to false if you don't want 
      // to retrigger another $stateChangeStart event
       $state.go("\");
      }
  }
  });
  </code></pre>
  
  <p>Any thoughts?</p>
  
  <p>Thanks,</p>
  
  <p>Jerry</p>