HTML 5和hashbang模式/链接重写之间的位置/切换我的印象是角将重写显示在tempaltes中锚标记的href属性中的URL,因此无论是在HTML 5模式还是在hashbang模式下,它们都可以工作。这个地点服务的文件似乎是说HTMLLink重写考虑了hashbang的情况。因此,我希望当不处于HTML 5模式时,会插入散列,而在HTML 5模式下,则不会插入散列。然而,似乎没有重写。下面的示例不允许我只更改模式。应用程序中的所有链接都需要手工重写(或者在运行时从变量派生)。是否需要根据模式手动重写所有URL?我没有看到任何客户端url重写在角1.0.6,1.1.4或1.1.3。似乎所有的href值都需要加上#/hashbang模式和/for HTML 5模式。是否有必要进行某些配置以导致重写?我是不是误读了医生?做别的傻事?下面是一个小例子:<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.3/angular.js"></script></head><body>
<div ng-view></div>
<script>
angular.module('sample', [])
.config(
['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
//commenting out this line (switching to hashbang mode) breaks the app
//-- unless # is added to the templates
$locationProvider.html5Mode(true);
$routeProvider.when('/', {
template: 'this is home. go to <a href="/about"/>about</a>'
});
$routeProvider.when('/about', {
template: 'this is about. go to <a href="/"/>home</a'
});
}
])
.run();
</script></body>增编:在重新阅读我的问题时,我发现我使用了“重写”一词,而不清楚我想要重写的人和时间。问题是如何获得角形在呈现路径时重写URL,以及如何让URL跨两种模式在JS代码中统一解释路径。它是不关于如何使Web服务器执行HTML 5兼容的请求重写。
3 回答

幕布斯6054654
TA贡献1876条经验 获得超7个赞
hashPrefix
:
appModule.config(['$locationProvider', function($locationProvider) { $locationProvider.html5Mode(true); $locationProvider.hashPrefix('');}]);
<head>
:
<head> <base href="/"> ...</head>
- 3 回答
- 0 关注
- 582 浏览
添加回答
举报
0/150
提交
取消