2

I am using AngularJS routing and I used many tricks, but the '#' sign always comes in URL.

Refer below Example/Code that I Used but it is not removing # sign from the URL.

angular.module('mod', []).
  config(['$routeProvider', '**$locationProvider'**, 
           function($routeProvider, **$locationProvider**) {

   $routeProvider.
      when('/first', { 
           templateUrl: 'first.html',   
           controller: 'firstCtrl'
   });

   $locationProvider.html5Mode(true);

  }]);

Does any one have solution for this? Please share it.

2 Answers 2

2

there are either of things u can do it work

you need to specify the base URL for the application with a If your root of your application is different than the url (for example /my-app, then use that as your base).

<head>
    <meta charset="utf-8">

    <base href="">  
</head>

or you can configure

$locationProvider.html5Mode({
  enabled: true,
  requireBase: false
});
Sign up to request clarification or add additional context in comments.

Comments

1

I've came up with the same issue and found the solution on the Docs.

$locationProvider.html5Mode({
  enabled: true,
  requireBase: false
});

and

<head>
  <base href="/">
  ...
</head>

If you configure $location to use html5Mode (history.pushState), you need to specify the base URL for the application with a tag or configure $locationProvider to not require a base tag by passing a definition object with requireBase:false to $locationProvider.html5Mode():

We've done the wrong function call. Try this and it will work. You can check the docs too.

1 Comment

Thanks, Let me try this :)

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.