本文介绍了角度-将参数附加到URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将参数附加到url:
I would like to append parameters to url:
let params = [];
params["p1"] = "value1";
params["p2"] = "value2";
this.location.go(this.router.createUrlTree([this.data]).toString());
当我使用此URL localhost/project/page
时,它的工作正确.但是当我在附加网址之后输入网址 localhost/project/page/id
后是 localhost/project/page/p1 = ..
When I have this url localhost/project/page
its work correct. But when I have url localhost/project/page/id
after append url is localhost/project/page/p1=..
我需要将参数保留在url中并添加新的参数.感谢您的建议
I need to keep the parameter in url and add the new one. thanks for advices
推荐答案
单击按钮时,调用下面的方法?这里 this.router
是 Router
实例,将其注入到您的组件中.
When you click the button, call a method like the one below?Here this.router
is Router
instance, inject it in your component.
onClick(params) {
this.router.navigate(['project', 'page', {id : id}], {queryParams: {p1: params['p1'], p2: params['p2']}});
}
这篇关于角度-将参数附加到URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!