Cannot match any routes. URL Segment: '': When trying to use child routes and Ng2

落花浮王杯 提交于 2019-12-08 02:56:32

问题


I have the following plunker, which does not work. In order to get it to work I can comment out...

RouterModule.forRoot([
      {
          path: "",
          component: TestComponent,
          children: [
              // {
              //    path:"",
              //    outlet: "other",
              //    component: TestComponent
              // }
          ]
      }
])

If I don't do that I get...

EXCEPTION: Uncaught (in promise): Error: Cannot match any routes. URL Segment: ''
Error: Cannot match any routes. URL Segment: ''

How do I add a child route?


回答1:


You should give different path names until you use pathMatch: 'full'. Forked.

More about the subject in Angular Router: Empty Paths, Componentless Routes, and Redirects.




回答2:


The router will stop after the first path is matched, which it does in the parent route. I've found it best to use a separate routing module for each router outlet. That being said, you get an ugly (other:route) for the auxilary route in your url. Admittedly, I have found some limitations to using auxiliary routes.



来源:https://stackoverflow.com/questions/40566685/cannot-match-any-routes-url-segment-when-trying-to-use-child-routes-and-ng

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!