Jackie
Jackie

Reputation: 23607

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

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?

Upvotes: 2

Views: 7289

Answers (2)

Roman C
Roman C

Reputation: 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.

Upvotes: 2

Nate May
Nate May

Reputation: 4072

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.

Upvotes: 1

Related Questions