Angular 2收到“错误:无法匹配任何路线:" [英] Angular 2 getting "Error: Cannot match any routes: ''"
问题描述
在我的Angular 2应用(RC4)中,当index.html打开时,我收到错误错误:无法匹配任何路线:''我知道以前曾有人问过这个问题,但这些情况下的答案似乎都不适用于我.也就是说,我已经在尽力建议解决此问题.我有
In my Angular 2 app (RC4), when the index.html opens, I get the error Error: Cannot match any routes: '' I know this has been asked before, but none of the answers in those cases seems to apply to me; that is, I"m already doing everything recommended to fix this. I have
<base href="/">
在我的头部元素中(也尝试过
in my head element (also tried
<base href=".">
完全没有区别).我的app.route.ts中包含以下内容:
which makes no difference at all). I have the following in my app.route.ts:
export const routes: RouterConfig = [
{ path: '', redirectTo: '/instruction-steps', pathMatch: 'full'},
{ path: 'settings', component: SettingsComponent },
{ path: 'find-and-replace', component: FindAndReplaceComponent },
{ path: 'instruction-steps', component: InstructionStepsComponent }
];
该页面确实可以正确呈现,并且我到其他视图的路线也可行.但是,如果我重新加载页面,不仅会得到错误,而且页面不会呈现.
The page does render correctly, and my routes to the other views work. If I reload the page, however, I'll not only get the error, but the page does not render.
这是在lite服务器而不是ASP.NET上运行的.
This is running on lite-server, not ASP.NET.
推荐答案
以下是一些注意事项:
- 确保将模块正确定义为
@NgModule
. - 确保已将路由模块正确添加到模块的导入中.
- 请确保正确拼写路径(例如,项目"与项目")
- 确保每个模块都已添加到主应用程序模块中.
请注意,这是从Angular 2的最终版本开始的.
Please note that this is as of the Final release of Angular 2.
这篇关于Angular 2收到“错误:无法匹配任何路线:"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!