3 回答

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超3個贊
在角度上有定位策略
查看app.module.ts在哪里啟動應(yīng)用程序
@NgModule({
.......
providers: [
....
{ provide: LocationStrategy, useClass: HashLocationStrategy },
....
]
});
并刪除此部分,因?yàn)镻athLocationStrategy是默認(rèn)策略

TA貢獻(xiàn)1877條經(jīng)驗(yàn) 獲得超1個贊
上面的答案具有從URL中刪除哈希的正確解釋,但是當(dāng)您更改LocationStrategy后端時,后端將無法理解所有Angular 2路由,因此會受到影響。以下是在后端支持下刪除哈希的步驟。
1)更改Angular以使用PathLocationStrategy
@NgModule({
.....
providers: [
// Below line is optional as default LocationStrategy is PathLocationStrategy
{provide: LocationStrategy, useClass: PathLocationStrategy}
]
})
2)在index.html中更改基準(zhǔn)Href,Angular2將處理基準(zhǔn)Href之后的所有路由
<base href="/app-context/">
例如
<base href="/app/">
3)在后端服務(wù)器上,對于任何以下格式的請求,我們都必須呈現(xiàn)index.html文件
"/app/**" - Render index.html for any request coming with "/app/**" pattern
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My App</title>
<base href="/app/">
</head>
<body>
<app-root>Loading...</app-root>
<script type="text/javascript" src="vendor.bundle.js"></script>
<script type="text/javascript" src="main.bundle.js"></script>
</body>
</html>
- 3 回答
- 0 關(guān)注
- 412 瀏覽
添加回答
舉報