Error: Uncaught (in promise): Error: Cannot match any routes Angular 2
I think that your mistake is in that your route should be product
instead of /product
.
So more something like
children: [
{
path: '',
component: AboutHomeComponent
},
{
path: 'product',
component: AboutItemComponent
}
]
I had to use a wildcard route at the end of my routes array.
{ path: '**', redirectTo: 'home' }
And the error was resolved.
For me it worked like the code below. I made a difference between RouterModule.forRoot
and RouterModule.forChild
. Then in the child define the parent path and in the children array the childs.
parent-routing.module.ts
RouterModule.forRoot([
{
path: 'parent', //parent path, define the component that you imported earlier..
component: ParentComponent,
}
]),
RouterModule.forChild([
{
path: 'parent', //parent path
children: [
{
path: '',
redirectTo: '/parent/childs', //full child path
pathMatch: 'full'
},
{
path: 'childs',
component: ParentChildsComponent,
},
]
}
])
Hope this helps.