Home > Software engineering >  What should I use to replace queryParamsHandling in Angular 12?
What should I use to replace queryParamsHandling in Angular 12?

Time:11-05

I had angular 10 appplication.In one of my pages i had the following code

this.router.navigateByUrl(SUPPORTED_URI.DEPLOYMENT_DASHBOARD, {queryParamsHandling: 'merge'});

after i updated my code to angular version 11, angular automatically removed queryParamsHandling from my code and now i have the following

                this.router.navigateByUrl(SUPPORTED_URI.DEPLOYMENT_DASHBOARD, /* Removed unsupported properties by Angular migration: queryParamsHandling. */ {});

what should I use now ? Why in angular there is no info about that this thing is depricated

https://angular.io/api/router/QueryParamsHandling

What should I use instead so my code will be not broken ?

CodePudding user response:

Angular split navigation options since v11, so you need to use createUrlTree method to build navigation tree and then navigate. Here is the comment explaining this.

So you need to update the code to something like this:

const urlTree = this.router.createUrlTree(SUPPORTED_URI.DEPLOYMENT_DASHBOARD, {queryParamsHandling: 'merge'});

this.router.navigateByUrl(urlTree);
  • Related