Reputation: 482
I'm kind of new in the Angular 4 world and I came across this error when I want to route to /moviegroup/:id. For some reason I can't make it to work
app.routes.ts
import { Routes, RouterModule, PreloadAllModules } from '@angular/router';
import { MovieComponent } from '.é/movie/movie.component';
import { WizardComponent } from './wizard/wizard.component';
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'wizard', component: WizardComponent, pathMatch: 'full' },
{
path: 'moviegroup',
children: [
{ path: 'moviegroup/:id', component: MovieComponent, pathMatch: 'full' }
]
}
];
export const routing = RouterModule.forRoot(routes, { preloadingStrategy:
PreloadAllModules });
I can navigate to http://localhost/wizard, http://localhost/moviegroup but not to http://localhost/moviegroup/ecf84479-c23c-1702-8440-b252591364ec. I get the following error:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'moviegroup/ecf84479-c23c-1702-8440-b252591364ec'
Error: Cannot match any routes. URL Segment: 'moviegroup/ecf84479-c23c-1702-8440-b252591364ec'
Any idea what I did wrong? If more info is required let me know!
Thanks, Reggi
Upvotes: 0
Views: 551
Reputation: 1663
Remove moviegroup
from the child path:
{
path: 'moviegroup',
children: [
{ path: ':id', component: MovieComponent }
]
}
And also you don't need to include pathMatch: 'full'
anywhere other than on empty route path with redirectTo
.
Upvotes: 1