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?

1
  • Actually, that sample site does not do what you're looking for. It's just hosted in a subdirectory. Commented Oct 3, 2013 at 17:49

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

@SangramSingh Check out this SO question. Keep in mind the history.pushState is a feature of HTML5, and it won't work on older browsers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.