Angular 激活的路由未找到我的查询参数
我试图在我的路径中获取一个参数,但当我试图打印它时,在我的控制台中返回undefined 这是我的路由模块:Angular 激活的路由未找到我的查询参数,angular,Angular,我试图在我的路径中获取一个参数,但当我试图打印它时,在我的控制台中返回undefined 这是我的路由模块: const routes: Routes = [ { path: ':id', component: ListaDadosPvSelecionadoComponent, canActivate: [AuthGuard], }, ]; 这就是我试图获取参数的方式: ngOnInit() { this.activatedRoute.queryPara
const routes: Routes = [
{
path: ':id',
component: ListaDadosPvSelecionadoComponent,
canActivate: [AuthGuard],
},
];
这就是我试图获取参数的方式:
ngOnInit() {
this.activatedRoute.queryParams.subscribe((params) => console.log(params['id']));
}
当我转到route/3
时,我的组件正在渲染,但我得到:
未定义
为什么?查询参数适用于
/domain?id=value
您可以对routes param使用snapshot.paramMap
this.activatedRoute.snapshot.paramMap.get('id')
params
和queryParams
是两个不同的东西
参数是URL/page/123
ngOnInit() {
this.activatedRoute.params.subscribe((params) => console.log(params.id));
}
查询参数是GET参数/page?id=123
ngOnInit() {
this.activatedRoute.params.subscribe((params) => console.log(params.id));
}
这是可行的,您能解释一下为什么queryParams不起作用,但paramMap.get()起作用吗?Query param对/domain有效吗?id=您需要使用snapshot.paramMap来路由id@veroneseComS