AngularJS 1.1.5 - automatically adding hash tag to URLs

夙愿已清 提交于 2019-12-30 00:54:08

问题


Does anyone know why version 1.1.5 automatically adds a hashtag to your urls, and how to turn this off? IMO this is ugly looking. It happens whenever you have a url that doesn't end in a forward slash. (I'm not using routes or anything like that).

So this:

http://my.website.com/about

becomes

http://my.website.com/about#/about

and this:

http://my.website.com/about.html

becomes:

http://my.website.com/about.html#/about.html

but this:

http://my.website.com/about/

doesn't have this problem.


回答1:


I experienced this issue just the other day. I solved it by enabling HTML5 mode for $locationProvider. See Docs for $location - HTML5 Mode Updated link for $location - HTML5 Mode.

It should look similar to this:

.config(['$locationProvider', function($locationProvider){
    $locationProvider.html5Mode(true).hashPrefix('!');
}]);



回答2:


This seems to be a bug introduced in angularjs 1.1.5 (since 1.1.4 does not exhibit this problem). I have reported the bug here:

https://github.com/angular/angular.js/issues/3083




回答3:


In $routeProvider set HTML5 mode as true as following

$locationProvider.html5Mode(true);

And in head section of your page add this following line

<base href="/">


来源:https://stackoverflow.com/questions/17350412/angularjs-1-1-5-automatically-adding-hash-tag-to-urls

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!