[英]Error: Cannot match any routes in Angular 4
I am lazy loading few modules in my Angular 4 app, with child routes to the lazy loaded module, but I am getting an error as Error: Cannot match any routes. URL Segment: 'order-management/list-view'
我在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'
when accessing the route. Error: Cannot match any routes. URL Segment: 'order-management/list-view'
访问路线时为Error: Cannot match any routes. URL Segment: 'order-management/list-view'
。
Here's my main app routing code: 这是我的主要应用程序路由代码:
{path: 'login', component: LoginComponent},
{path: 'order-management', loadChildren: './order-management/order-management.module#OrderManagementModule'},
{path: '', redirectTo: '/login', pathMatch: 'full'}
and here's the routing code for the lazy loaded OrderManagementModule
: 这是延迟加载的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'},
]}
Assume the code to load each child component in the path /order-management/SOME_CHILD_COMPONENT
and also redirect /order-management
path to /order-management/list-view
. 假定代码将每个子组件加载到路径/order-management/SOME_CHILD_COMPONENT
,并将/order-management
路径重定向到/order-management/list-view
。 I am not sure, what went wrong here. 我不确定,这里出了什么问题。 Please solve this issue. 请解决此问题。
You should remove the pathMatch: 'full'
from the first path
where you already defined a component: OrderManagementComponent
. 您应该从已定义component: OrderManagementComponent
的第一个path
pathMatch: 'full'
删除pathMatch: 'full'
。
You cannot have a pathMatch
in combination with a component
. 您不能将pathMatch
与component
结合使用。 Perhaps angular
should have already thrown an error for that. 也许angular
应该已经为此抛出了错误。 pathMatch
is used for redirects, which means that if you have a pathMatch
property in your route, you should have a redirectTo
as well. pathMatch
用于重定向,这意味着,如果您的路由中具有pathMatch
属性,则也应该具有redirectTo
。
I'll have to dig into the source of the angular router, to see why it would throw this error: 我必须深入研究角度路由器的来源,以了解为什么会引发此错误:
Cannot match any routes. 无法匹配任何路线。 URL Segment: 'order-management/list-view' 网址段:“订单管理/列表视图”
But if I have to guess, I think that it sees the pathMatch
property, and tries to redirect. 但是,如果我不得不猜测,我认为它看到了pathMatch
属性,并尝试重定向。 But redirect to what? 但是重定向到什么? There is no redirectTo
property. 没有redirectTo
属性。 My guess is that it tries to some unknown route, maybe with undefined
, and it will throw an error. 我的猜测是,它尝试使用未知路径(可能带有undefined
,并且会引发错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.