angular - 使用多子时如何使用routerLink?

标签 angular angular2-routing

这是 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
                        },
                    ]
                }

            ]
        },
    ]
  },

我想获取 List LocauxComponent 通过单击企业 ID 以获取此 URL localhost:3000/adminHome/users/{{id_user}}/{{id_entreprise}} 我试试
[routerLink]="['/adminHome/users/:id',x.id]" 但我得到另一个类似的网址 http://localhost:3000/adminHome/users/%3Aid/58e35bdeaf314301ec86c249

最佳答案

您的链接有误。使用 [routerLink] 时,您不需要指定 :id,就像您不需要使用路径变量那样,它被定义为占位符放置 id。

[routerLink] 应该如下所示:

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

编辑

为了构建具有更多参数的[routerLink],请执行以下操作:

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

这将导致:/adminHome/users/1/2 如果 param1=1param2=2

关于angular - 使用多子时如何使用routerLink?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43203848/

相关文章:

Angular 路由器 : Why do we need both: guards and events?

Angular 2 路由器在 Resolve 中使用 BehaviorSubject Observable

Angular 2 - 无法从路由器获取网址

angular - 像 Turn Js 这样的 Ionic 2 动画书

unit-testing - 带有可观察对象的单元测试模拟服务 => 订阅不是函数

Angular2 路由器和一个路由中的多个解析

Angular 2 从 ComponentInstruction 获取 URL

angular - 如何访问禁用输入的值?

Angular:模块延迟加载和缺少 block

javascript - 使用 ng update 升级到 ng9/ivy 时出错