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

编程入门 行业动态 更新时间:2024-10-07 22:26:33
本文介绍了Angular 2收到“错误:无法匹配任何路线:"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的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收到“错误:无法匹配任何路线:"

    本文发布于:2023-11-25 21:36:53,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1631440.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:路线   错误   Angular   quot

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!