这里是我的项目目录结构: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? –