javascript AngularJS 1.1.5 - 自动向 URL 添加哈希标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17350412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
AngularJS 1.1.5 - automatically adding hash tag to URLs
提问by Kevin Beal
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).
有谁知道为什么 1.1.5 版会自动向您的网址添加主题标签,以及如何将其关闭?IMO 这看起来很丑。只要您的网址不以正斜杠结尾,就会发生这种情况。(我没有使用路线或类似的东西)。
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.
没有这个问题。
回答by EnigmaRM
I experienced this issue just the other day. I solved it by enabling HTML5 mode for $locationProvider
. See Docs for $location - HTML5 ModeUpdated link for $location - HTML5 Mode.
前几天我遇到了这个问题。我通过为$locationProvider
. 看$location 文档 - HTML5 模式更新了 $location - HTML5 模式的链接。
It should look similar to this:
它应该类似于:
.config(['$locationProvider', function($locationProvider){
$locationProvider.html5Mode(true).hashPrefix('!');
}]);
回答by jssebastian
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:
这似乎是 angularjs 1.1.5 中引入的一个错误(因为 1.1.4 没有出现这个问题)。我在这里报告了错误:
回答by vijay
In $routeProvider set HTML5 mode as true as following
在 $routeProvider 中将 HTML5 模式设置为 true 如下
$locationProvider.html5Mode(true);
And in head section of your page add this following line
并在页面的头部部分添加以下行
<base href="/">