I need to add queryParams dynamically to url without reloading page. So I carried out using the Location service as below,
this.location.go(`${path}?tab=xxx`); // works perfectly without page reload
Now the problem is when I try to access the queryParams it returns empty.
this.activatedRoute.queryParams.subscribe((qp) => {
console.log('updated queryParams', qp); // returns {}
});
whereas when the same code works if the page is reloaded properly. Any way to the same without refreshing the page in angular or should I try with native js?
this.activatedRoute.queryParams.subscribeit returns {}locationservice doesn't listen theactivatedRoute.QueryParams. whereasthis.router.navigate(['.'], { relativeTo: this.route, queryParams: { 'tab': 'xxx' }});listens to the subscribe method as well as doesn't reload the page. Thanks @AndreiTătar for pointing out the question.