這裏是我的項目目錄結構:Angular2路線:使用HashLocationStrategy有一個404未找到錯誤
--root
--app
--app.ts
--boot.ts
--index.html
--node_modules
這裏是我的代碼:
boot.ts
bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(LocationStrategy, {useClass: HashLocationStrategy})
]);
app.ts
@RouteConfig([
{path: '/', name: 'root', redirectTo: ['/pageA']},
{path: '/page-a', name: 'pageA', component: PageA},
{path: '/page-b', name: 'pageB', component: PageB}
])
html文件:
<head>
<base href="/">
<script src="node_modules/angular2/bundles/router.dev.js"></script>
...
</head>
它的工作原理,但是當我看到控制檯,它告訴我"http://localhost:63342/#/page-a Failed to load resource: the server responded with a status of 404 (Not Found)"
此外,當我刷新頁面,它顯示了「404未找到」頁面。
我真的試圖b其他方式,但有同樣的錯誤。順便說一句,爲什麼你更喜歡useAsDefault? useAsDefault比redirectTo更好嗎? –
這允許你不寫「/」的特殊/假路由... –
你使用哪個Angular2? –