I need help in my routing in Angular 4. I want to display the URL like this. Localhost:4200/user/1 if i clicked the view details of the first user. I'm a bit confused on how to to this. I've tried my best in my code below but it still doesn't work.
app-routing.module.ts
const appRoutes: Routes = [
{ path: '', redirectTo: '/dashboard', pathMatch: 'full' },
{ path: 'dashboard', component: DashboardComponent },
{ path: 'user', component: UserComponent, children: [
{ path: 'create-new-user', component: CreateNewUserComponent },
{ path: 'user-list', component: UserListComponent },
{ path: 'user-detail/:id', component: UserDetailComponent },
]},
];
@NgModule({
imports: [RouterModule.forRoot(appRoutes)],
exports: [RouterModule]
})
export class AppRoutingModule {
}
It should be something like this
If you want the url as listed
/user/1
then change the router configuration to match the name i:e instead ofuser-detail
change touser
UPDATE
Ya there is change the template line to this