I have a problem regarding the routing in Angular 5. I would like to create a child route but when i type the url (for child route) the parent component gets loaded. My routing:
path: 'user-admin/:id',
component: UserAdminComponent,
},
children: [
{
path: '',
component: UserAdminComponent,
pathMatch: 'full'
},
{
path: "final-exams",
component: FinalExamsComponent,
},
The two routes that belongs to the problem:
http://localhost:4200/user-admin/0
http://localhost:4200/user-admin/0/final-exams
Thank you for your help in advance! :)
Have a look at the working solution
Stack Blitz, Source Code
user-admin/1 // Hello will be printed
user-admin/1/final-exams // Hola will be the output
Problem was:
You mentioned the same component in both Parent and Child Route & Children routes were not mentioned inside the parent route
const appRoutes: Routes = [
{
path: 'user-admin/:id',
// component: HelloComponent, // No need to mention the same component, in parent
children: [ // Children routes are inside the parent route
{
path: '',
component: HelloComponent,
pathMatch: 'full'
},
{
path: "final-exams",
component: HolaComponent
}
]
}
];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With