繁体   English   中英

错误:无法匹配Angular 4中的任何路线

[英]Error: Cannot match any routes in Angular 4

我在Angular 4应用程序中延迟加载了一些模块,并带有到延迟加载模块的子路由,但由于出现Error: Cannot match any routes. URL Segment: 'order-management/list-view' ,我遇到了错误Error: Cannot match any routes. URL Segment: 'order-management/list-view' Error: Cannot match any routes. URL Segment: 'order-management/list-view'访问路线时为Error: Cannot match any routes. URL Segment: 'order-management/list-view'

这是我的主要应用程序路由代码:

  {path: 'login', component: LoginComponent},
  {path: 'order-management', loadChildren: './order-management/order-management.module#OrderManagementModule'},
  {path: '', redirectTo: '/login', pathMatch: 'full'}

这是延迟加载的OrderManagementModule的路由代码:

    {path: '', component: OrderManagementComponent, pathMatch: 'full', children: [
        {path: 'list-view', component: ListComponent},
        {path: 'column-view', component: ColumnComponent},
        {path: 'comfy-view', component: ComfyComponent},
        {path: '', redirectTo: '/order-management/list-view', pathMatch: 'full'},
  ]}

假定代码将每个子组件加载到路径/order-management/SOME_CHILD_COMPONENT ,并将/order-management路径重定向到/order-management/list-view 我不确定,这里出了什么问题。 请解决此问题。

您应该从已定义component: OrderManagementComponent的第一个path pathMatch: 'full'删除pathMatch: 'full'

您不能将pathMatchcomponent结合使用。 也许angular应该已经为此抛出了错误。 pathMatch用于重定向,这意味着,如果您的路由中具有pathMatch属性,则也应该具有redirectTo

我必须深入研究角度路由器的来源,以了解为什么会引发此错误:

无法匹配任何路线。 网址段:“订单管理/列表视图”

但是,如果我不得不猜测,我认为它看到了pathMatch属性,并尝试重定向。 但是重定向到什么? 没有redirectTo属性。 我的猜测是,它尝试使用未知路径(可能带有undefined ,并且会引发错误。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM