1

I would like to append the browser url based on the view enabled in the same page.

Default URL: http://localhost:4200/xxx/disciplines

On click on the table row it will update like URL: http://localhost:4200/xxx/disciplines?disciplineId=1100

onRowClicked(event: any) {
    this.isRowSelected = true;
    this.selectedId = event.data.id; //event.id;
    this.selectedItem = event;
    console.log(this.selectedItem);
    this.dataService.set(event);
    this.router.navigate([], { queryParams: { disciplineId: this.selectedId } });

  }
  1. Can not we update the selected ID automatically without using this.router.navigate([], { queryParams: { disciplineId: this.selectedId } });

  2. How to append the new value like http://localhost:4200/xxx/disciplines?disciplineId=1100&disciplineView=create on clicking on some button.

If I use this this.router.navigate([], { queryParams: { disciplineView: view } });

url changed to

http://localhost:4200/xxx/disciplines?disciplineView=create

instead

http://localhost:4200/xxx/disciplines?disciplineId=1100&disciplineView=create

Expert advise please?

6
  • 1
    Possible duplicate of Angular 2 updating URL path params with no redirect Commented Jun 17, 2019 at 4:53
  • If I get your question right, On first click of the button, you need http://localhost:4200/xxx/disciplines?disciplineId=1100 and on the second click of the same button you need http://localhost:4200/xxx/disciplines?disciplineId=1100&disciplineView=create? Commented Jun 17, 2019 at 4:55
  • If you want the above, you should use queryParamsHandling: "merge" . like this: this.router.navigate([], { queryParams: { disciplineView: view }, queryParamsHandling: "merge" }); Commented Jun 17, 2019 at 4:57
  • Check this link for more info. Commented Jun 17, 2019 at 4:58
  • 1
    Ok you can follow my option on using queryParamsHandling: "merge" above. Commented Jun 17, 2019 at 5:00

1 Answer 1

0

You should use queryParamsHandling: "merge" . like this: this.router.navigate([], { queryParams: { disciplineView: view }, queryParamsHandling: "merge" });

So this will merge your new params to the existing activated route.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.