Angular路由器导航不会为连续请求更新url参数



我正在尝试使用路由器导航更新查询参数

updateURL(queryParams){
this.router.navigate(['path], {
relativeTo: this.route,
queryParams: queryParams,
queryParamsHandling: 'merge',
skipLocationChange: false
});
}
/** Wont Work 
updateURL(queryParams);
updateURL(queryParams);
updateURL(queryParams);
/** Will Work
updateURL(queryParams);
// wait
updateURL(queryParams);
// wait
updateURL(queryParams)

当顺序调用此方法以更新URL查询参数时,angular不会更新URL。如何处理它,以便即使在进行顺序调用时也能更新url

从文档中可以看出,您将不得不等待下一次更新

navigate(commands: any[], extras: NavigationExtras = { skipLocationChange: false }): Promise<boolean>

你能试试这个吗

async updateURL(queryParams){
await this.router.navigate(['path], {
relativeTo: this.route,
queryParams: queryParams,
queryParamsHandling: 'merge',
skipLocationChange: false
});
}
async UpdateQueryParam() {
await updateURL(queryParams);
await updateURL(queryParams);
await updateURL(queryParams)
}

最新更新