简体   繁体   English

Angular 2收到“错误:无法匹配任何路线:”

[英]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: 这里有一些注意事项:

  1. Be sure that modules are properly defined as @NgModule . 确保将模块正确定义为@NgModule
  2. Be sure that routing modules are properly added to imports for the module. 确保已将路由模块正确添加到模块的导入中。
  3. Be sure that paths are spelled correctly (eg "item" vs. "items") 确保正确拼写路径(例如,“项目”与“项目”)
  4. Be sure that each module is added to the main App Module. 确保将每个模块都添加到主应用程序模块中。

Please note that this is as of the Final release of Angular 2. 请注意,这是从Angular 2的最终版本开始的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular 2 Uncaught(承诺):错误:无法匹配任何路线。 URL段:&#39;aboutme&#39;错误:无法匹配任何路由。 网址段:aboutme - Angular 2 Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'aboutme' Error: Cannot match any routes. URL Segment: aboutme 带有参数的Angular嵌套路由“无法匹配任何路由” - Angular nested route with param “Cannot match any routes” EXCEPTION:错误:未捕获(在承诺中):错误:无法匹配任何路由:''“ - EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: ''" 错误:未捕获(承诺):错误:无法匹配任何路由RC4子路由 - Error: Uncaught (in promise): Error: Cannot match any routes RC4 Child Routes 错误:未捕获(承诺):错误:无法匹配任何路由。 网址区隔:&#39;parent / child1 - How to configure child routes properly?Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'parent/child1 离子 - 导航到具有特定 ID 错误的离子选项卡页面:无法匹配任何路由。 URL 段: - Ionic - Navigate to a Ionic Tabs page with a specific Id Error: Cannot match any routes. URL Segment: 如何匹配带有angular2 rc5的APP MODULE TS中的任何路线? - How to match any routes in APP MODULE TS with angular2 rc5? Angular 2:指令和路由出错 - Angular 2 : Error with directives and routes 得到错误 - 找不到名字&#39;angular&#39; - Getting Error - Cannot find name 'angular' 角路线没有任何输出 - Angular Routes not giving me any output
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM