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 關注
- 617 瀏覽
添加回答
舉報
0/150
提交
取消