HTML 5和hashbang模式/鏈接重寫(xiě)之間的位置/切換我的印象是角將重寫(xiě)顯示在tempaltes中錨標(biāo)記的href屬性中的URL,因此無(wú)論是在HTML 5模式還是在hashbang模式下,它們都可以工作。這個(gè)地點(diǎn)服務(wù)的文件似乎是說(shuō)HTMLLink重寫(xiě)考慮了hashbang的情況。因此,我希望當(dāng)不處于HTML 5模式時(shí),會(huì)插入散列,而在HTML 5模式下,則不會(huì)插入散列。然而,似乎沒(méi)有重寫(xiě)。下面的示例不允許我只更改模式。應(yīng)用程序中的所有鏈接都需要手工重寫(xiě)(或者在運(yùn)行時(shí)從變量派生)。是否需要根據(jù)模式手動(dòng)重寫(xiě)所有URL?我沒(méi)有看到任何客戶端url重寫(xiě)在角1.0.6,1.1.4或1.1.3。似乎所有的href值都需要加上#/hashbang模式和/for HTML 5模式。是否有必要進(jìn)行某些配置以導(dǎo)致重寫(xiě)?我是不是誤讀了醫(yī)生?做別的傻事?下面是一個(gè)小例子:<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>增編:在重新閱讀我的問(wèn)題時(shí),我發(fā)現(xiàn)我使用了“重寫(xiě)”一詞,而不清楚我想要重寫(xiě)的人和時(shí)間。問(wèn)題是如何獲得角形在呈現(xiàn)路徑時(shí)重寫(xiě)URL,以及如何讓URL跨兩種模式在JS代碼中統(tǒng)一解釋路徑。它是不關(guān)于如何使Web服務(wù)器執(zhí)行HTML 5兼容的請(qǐng)求重寫(xiě)。
3 回答

幕布斯6054654
TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超7個(gè)贊
hashPrefix
:
appModule.config(['$locationProvider', function($locationProvider) { $locationProvider.html5Mode(true); $locationProvider.hashPrefix('');}]);
<head>
:
<head> <base href="/"> ...</head>
- 3 回答
- 0 關(guān)注
- 610 瀏覽
添加回答
舉報(bào)
0/150
提交
取消