【发布时间】:2021-09-17 12:28:51
【问题描述】:
我想将 HttpParams 类的实例传递给路由查询参数
const params: HttpParams = new HttpParams().set('page', '2')
this.router.navigate([''],{queryParams: params.toString()});
我得到了一个错误:
Type 'string' is not assignable to type 'Params | null | undefined'
如果我直接传递参数而不转换为字符串,我不会得到正确的结果 得到这样的东西:
?encoder=%5Bobject%20Object%5D&map=%5Bobject%20Map%5D
【问题讨论】:
-
你应该使用NavigationExtras来处理这种事情。
标签: angular parameters routes query-parameters