o.O
o.O

Reputation: 155

how to use routerLink when using multi children?

this is AdminRouting

    path: 'adminHome',
    component: adminHomeComponent,
    children: [
        {
            path: '',
            component: HomeComponent,

        },
        {
            path: 'home',
            component: HomeComponent,

        },
        {
            path: 'users',
            component: UserListComponent,
            children: [
                {
                    path: '',
                    component: HUComponent
                },
                {
                    path: ':id',
                    component: EntrepriseListComponent,
                    children: [
                        {
                            path: '',
                            component: HyComponent

                        },
                        {
                            path: ':id',
                            component: ListLaucauxComponent
                        },
                    ]
                }

            ]
        },
    ]
  },

I want to get List LocauxComponent By clicking on id of the enterprise in order to get this URL localhost:3000/adminHome/users/{{id_user}}/{{id_entreprise}} I try with
[routerLink]="['/adminHome/users/:id',x.id]" but i get another URL something like http://localhost:3000/adminHome/users/%3Aid/58e35bdeaf314301ec86c249

Upvotes: 3

Views: 5463

Answers (1)

Tom
Tom

Reputation: 3850

Your link is wrong. When using the [routerLink] you don't need to specift the :id the same as you dont need to do that with a path variable, it is defined as a placeholder to put the id.

The [routerLink] should look something like the following:

[routerLink]="['/adminHome/users', x.id]"

EDIT

In order to build the [routerLink] with more paramaters do the following:

[routerLink]="['/adminHome/users', param1, param2...]"

That will result in : /adminHome/users/1/2 if param1=1 and param2=2

Upvotes: 1

Related Questions