title: Set up redirect with ui-router/Angular JS
body: <p>I would like to setup some redirects in my angular app. </p>
  
  <p>Right now I have:</p>
  
  <pre><code>$urlRouterProvider.otherwise('/notfound');
  </code></pre>
  
  <p>So if path doesnt match any of the defined states, it will go to the "not found" state. </p>
  
  <p>However, I would like to modify this behavior such that when a path doesnt match any of the defined states, angular checks against an array of redirects first. If none match, it will go to "not found". If there is a match, angular will do a hard redirect to the matching URL. </p>
  
  <p>In pseudo code:</p>
  
  <pre><code>var redirects = [{'/a_certain_path':'http://www.someaddress.com/'}];
  
  if(URL != defined state){  // path doesnt match any state
  
      if( URL in redirects araay ){ // path matches value in array
  
          window.location = redirects[URL]; // redirect to match
  
      } else  $state.go('base.notfound');  
  
  } else {
  
      $state.go('base.notfound');
  }
  </code></pre>
  
  <p>Ive tried a few thing (like using resolve in my 'not found' state) but obviously this doesnt work because the path is already "/notfound" by the time I get there. </p>