AngularJS 1.1.5-自动向URL添加哈希标签

AngularJS 1.1.5 - automatically adding hash tag to URLs

本文关键字:添加 哈希 标签 URL AngularJS      更新时间:2023-09-26

有人知道1.1.5版本为什么会自动在你的url中添加一个标签,以及如何关闭这个标签吗?IMO这看起来很难看。只要你的url不是以斜杠结尾,就会发生这种情况。(我不使用路线或类似的东西)。

所以这个:

http://my.website.com/about

成为

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

这个:

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

变为:

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

但是这个:

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

没有这个问题。

前几天我遇到了这个问题。我通过为$locationProvider启用HTML5模式解决了这个问题。请参阅$location-HTML5模式的

文档$location-HHTML5模式的更新链接。

它应该看起来像这样:

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

这似乎是angularjs 1.1.5中引入的一个错误(因为1.1.4没有出现这个问题)。我在这里报告了错误:

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

在$routeProvider中,将HTML5模式设置为true,如下所示

$locationProvider.html5Mode(true);

在页面的首页添加以下行

<base href="/">