0

I am getting the following error after configuring child routes.

Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'parent/child1

app.routing.ts

{ path: 'home', component: homeComponent},
  { path: 'about', component: aboutComponent},
  { path: 'parent', component: parentComponent,
    children:[
    {
      path: '',
      redirectTo: '/parent/child1',
      pathMatch: 'full'
    },
    {
      path: 'child1',
      component: child1Component,
      outlet: 'subRouter'
    },
    {
      path: 'child2',
      component: child2Component,
      outlet: 'subRouter'
    }]
  },
{ path: '**', redirectTo: 'home', pathMatch: 'full' }

In my index.html, I have <router-outlet></router-outlet>

In my parent.htm(parentComponent) I have <router-outlet name="subRouter"></router-outlet>

What am i missing? Why i am getting that error? How can i resolve this error?

Keshav1007
  • 605
  • 2
  • 8
  • 21

1 Answers1

0

The parent route children '' path redirection should changed to below, and explicitly mention outlet:component value.

redirectTo: '/child1(subRouter:child1)'

Because /parent will be implicitly included as you're redirecting from child route.

Pankaj Parkar
  • 134,766
  • 23
  • 234
  • 299