Doob Doob - 4 months ago 27x
AngularJS Question

AngularJS routing without the hash '#'

I'm learning AngularJS and there's one thing that really annoys me.

I use

to declare routing rules for my application:

$routeProvider.when('/test', {
controller: TestCtrl,
templateUrl: 'views/test.html'
.otherwise({ redirectTo: '/test' });

but when I navigate to my app in browser I see
instead of

So my question is why AngularJS adds this hash
to urls? Is there any possibility to avoid it?


In fact you need the # (hashtag) for non HTML5 browsers.

Otherwise they will just do an HTTP call to the server at the mentioned href. The # is an old browser shortcircuit which doesn't fire the request, which allows many js frameworks to build their own clientside rerouting on top of that.

You can use $locationProvider.html5Mode(true) to tell angular to use HTML5 strategy if available.

Here the list of browser that support HTML5 strategy: