Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular - append params to 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());

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=..

I need to keep the parameter in url and add the new one. thanks for advices

like image 247
bluray Avatar asked Feb 25 '26 13:02

bluray


1 Answers

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']}});
}
like image 141
Ashish Ranjan Avatar answered Feb 27 '26 03:02

Ashish Ranjan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!