[英]Angular 2 getting “Error: Cannot match any routes: ''”
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; 在我的Angular 2应用程序(RC4)中,当index.html打开时,出现错误错误:无法匹配任何路径:''我知道之前曾有人问过,但是在这些情况下,没有答案似乎适用于我; that is, I"m already doing everything recommended to fix this. I have
也就是说,我已经在尽力建议解决此问题。
<base href="/">
in my head element (also tried 在我的头元素中(也尝试过
<base href=".">
which makes no difference at all). 这一点都没有区别)。 I have the following in my app.route.ts:
我的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.
但是,如果我重新加载页面,不仅会得到错误,而且页面不会呈现。
This is running on lite-server, not ASP.NET. 它运行在lite服务器上,而不是ASP.NET上。
由于信誉低,我无法发表评论,但是您是否在asp.net中使用angular 2,那么您必须在startup.cs中添加代码,以在找不到路由时指向使用index.html。
Have you tried to change the order and put like that: 您是否尝试过更改订单并像这样放置:
export const routes: RouterConfig = [
{ path: 'settings', component: SettingsComponent },
{ path: 'find-and-replace', component: FindAndReplaceComponent },
{ path: 'instruction-steps', component: InstructionStepsComponent }
{ path: '', redirectTo: '/instruction-steps', pathMatch: 'full'}
];
Here are a few tips to watch out for: 这里有一些注意事项:
@NgModule
. @NgModule
。 Please note that this is as of the Final release of Angular 2. 请注意,这是从Angular 2的最终版本开始的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.