I assure you, this question is not a duplicate. Please read the question first before discarding it.
First look at the code then I'll explain.
constructor(private router: Router, private activatedRoute: ActivatedRoute) {
}
private someFunction(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
if (route.queryParams.hasOwnProperty('rew')) {
const url = new URL((new URL(window.location.href)).origin + state.url.toString());
url.searchParams.delete('rew');
let queryParams: Record<string, string> = {};
url.searchParams.forEach((value, key) => {
queryParams[key] = value;
});
this.router.navigate(['.'], { relativeTo: this.activatedRoute, queryParams: queryParams }).catch(console.log);
}
return true;
}
As you can see I have a function, in which I'm checking if the queryParams contain 'rew' and then remove it. Then redirect to the same page with the updated queryParams.
But redirection is not working.
How to redirect to the same page with updated queryParams? Remember the page linking is dynamic, so static links like this this.route.navigate('/contact')
won't work.