Jonathan Solorzano
Jonathan Solorzano

Reputation: 7022

Appropriate way to declare child routes in Angular 2

I got a UsersModule with the following routing:

export const UsersRoutingModule = RouterModule.forChild([
  {
    path: 'users', component: UsersComponent,
    children: [
      { path: ':id', component: DetailUserComponent },
      { path: 'add', component: AddUserComponent },
      { path: 'edit', component: EditUserComponent }
    ]
  }
]);

Problem is when I access to /users/anything it always displays the DetailUserComponent, so, using child routes, How do I have to declare the children routes for users?

Upvotes: 0

Views: 129

Answers (1)

Vova Bilyachat
Vova Bilyachat

Reputation: 19494

try to change routing

export const UsersRoutingModule = RouterModule.forChild([
  {
    path: 'users', component: UsersComponent,
    children: [
      { path: 'add', component: AddUserComponent },
      { path: 'edit', component: EditUserComponent },
      { path: ':id', component: DetailUserComponent },
    ]
  }
]);

Because in your routing id doesnot have any limits so even something can become an id

Upvotes: 1

Related Questions