首页 > 解决方案 > 如何在 Angular 中检索夹层/内部 URL 参数?

问题描述

所以我的 url 路由是 'players/:id/listview'

(listview 是 objects 组件的子组件)

我的路由模块:

path: 'players/:id',
    component: PlayersComponent,
    children: [
        { path: '', redirectTo: 'listview' },
        { path: 'listview', component: ListviewComponent }
    ]

我试过了

this.route.snapshot.paramMap.get("id")

输出:空

然后我尝试了

this.route.snapshot.param

输出: {}

如何从这条路线获取 id?

标签: angularparametersrouter

解决方案


您可以访问当前路由的父级:

this.route.parent.snapshot.paramMap.get("id")

推荐阅读