简体   繁体   English

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

[英]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 . 您不能将pathMatchcomponent结合使用。 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.

相关问题 无法匹配任何路线Angular 6上的错误 - Cannot match any routes Error on Angular 6 无法匹配任何路线。 角度误差? - Cannot match any routes. Error in angular? Angular 4 throw与URL中的XSS脚本无法匹配任何路由错误 - Angular 4 throwing Cannot match any routes error with XSS script in URL 未捕获(承诺):错误:无法匹配任何路线(Angular8) - Uncaught (in promise): Error: Cannot match any routes (Angular8) 未捕获(承诺):错误:无法匹配任何路由:“” - Uncaught (in promise): Error: Cannot match any routes: ' ' Angular CLI Deploy to Github Pages问题:错误错误:未捕获(承诺):错误:无法匹配任何路由 - Angular CLI Deploy to Github Pages issue: ERROR Error: Uncaught (in promise): Error: Cannot match any routes 角单元测试:未捕获错误:未捕获(承诺中):错误:无法匹配任何路线。 网址段:“注销” - Angular Unit Test: Uncaught Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'logout' Angular 5(IE11)错误:未捕获(承诺):错误:无法匹配任何路由 - Angular 5 (IE11) Error: Uncaught (in promise): Error: Cannot match any routes Angular 测试:未捕获错误:未捕获(承诺中):错误:无法匹配任何路由。 URL 段:“家” - Angular Testing: Uncaught Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'home' 角度4:后备路由(pathMatch)无法正确重定向到后备网址,错误:未捕获(承诺):错误:无法匹配任何路由 - Angular 4: Fallback routes(pathMatch) doesn't redirect correctly to the fallback url, Error: Uncaught (in promise): Error: Cannot match any routes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM