3

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

2 Answers 2

2

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']}});
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks but I think, this updates my page. I dont want it. does the id stay in the url?
If there is an id add the variable under the navigate method.
Ok but sometimes I dont have id in url.
0

You can send params in the routing like below -

[routerLink]="['project/page','params']"

If you wish to send it as query params send it like this -

<a [routerLink]="['project/page']" [queryParams]="{ page: 99 }">Your caption</a>

1 Comment

I can not use this. I would like to add param to url after click for button and I can not redirect page.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.