0

using ng-view and

myApp.config(['$routeProvider', function($routeProvider) {
  $routeProvider.
      when('/', {
        templateUrl: '/partials/home',
        controller: 'homePage'
      }).      
      otherwise({redirectTo: '/login'});
}]);

everything works fine, except the URL, which shows /#/ before each address. How do you get rid of it?

Sangram Singh
  • 7,161
  • 15
  • 50
  • 79
  • Actually, that sample site does not do what you're looking for. It's just hosted in a subdirectory. – SLaks Oct 03 '13 at 17:49

1 Answers1

4

inject $locationProvider and set html5mode to true http://docs.angularjs.org/guide/dev_guide.services.$location

myApp.config(['$routeProvider','$locationProvider', function($routeProvider, $locationProvider) {
  $routeProvider.
      when('/', {
        templateUrl: '/partials/home',
        controller: 'homePage'
      }).      
      otherwise({redirectTo: '/login'});
  $locationProvider.html5Mode(true);        // <-- Here comes the magic
}]);

remember though that you will need to set upp the backend to redirect all links to index.html

Nils Larson
  • 488
  • 4
  • 14
  • @SangramSingh Check out this [SO](http://stackoverflow.com/questions/11095179/using-html5-pushstate-on-angular-js) question. Keep in mind the `history.pushState` is a feature of HTML5, and it won't work on older browsers. – Michael Benford Oct 03 '13 at 17:42