title: How to remove redirects in Rails/Angularjs html5 mode
body: <p>How can I avoid the performance hit each time a user refreshes an angularjs page when using html 5 mode with rails? I am using Angularjs html5 mode Ruby on Rails route redirects. With my setup if I visit <code>http://localhost:3000/users</code> the url immediately becomes <code>http://localhost:3000/?goto=users</code> which then redirects to <code>http://localhost:3000/users</code>. What can I do to avoid redirects of this nature when using html5 mode?</p>
  
  <h1>Rails Routes</h1>
  
  <pre><code>myApp::Application.routes.draw do
   namespace :api, defaults: {format: :json} do
     namespace :v1 do
      resources :users
     end
   end
  
  # Re-route all angular requests to the angular router
  get "/*path" =&gt; redirect("/?goto=%{path}")
  root to: 'application#home'
  </code></pre>
  
  <p>end</p>
  
  <h1>Angular Routes</h1>
  
  <pre><code>myApp.config(function($routeProvider, $locationProvider, $httpProvider) {
      $httpProvider.defaults.headers.common['X-CSRF-Token'] = 
      $('meta[name=csrf-token]').attr('content');
      $routeProvider.
          when('/', {
              templateUrl: '../assets/mainIndex.html',            
              controller: 'MainController',
              redirectTo:
                  function(current, path, search){
                    if(search.goto){
                      // if we were passed in a search param, and it has a path
                      // to redirect to, then redirect to that path
                      return "/" + search.goto;
                    }
                    else{
                      // else just redirect back to this location
                      // angular is smart enough to only do this once.
                      return "/";
                    }
                  }
          }).when('/users', {
              templateUrl: '../assets/users/userIndex.html',          
              controller: 'UsersController'
          }).otherwise({
              redirectTo:'/'
          });
      $locationProvider.html5Mode(true);
  });
  </code></pre>
  
  <p>The above is from this blog: <a href="http://omarriott.com/aux/angularjs-html5-routing-rails/" rel="nofollow">http://omarriott.com/aux/angularjs-html5-routing-rails/</a></p>