set queryparams angular code example

Example 1: angular set query params

constructor(private router: Router) { }

public myMethodChangingQueryParams() {
  const queryParams: Params = { myParam: 'myNewValue' };

  this.router.navigate(
    [], 
    {
      relativeTo: activatedRoute,
      queryParams: queryParams, 
      queryParamsHandling: 'merge', // remove to replace all query params by provided
    });
}

Example 2: queryparams angular

Query parameters in Angular allow for passing optional parameters across any route in the application. Query parameters are different from regular route parameters, which are only available on one route and are not optional (e.g., /product/:id).

Example 3: angular set url parameters

//in your HTML code :
<a href="javascript:;" routerLink="/link/params">
  My link
</a>

// app-routing.module.ts:
//in your Routes array :
{path: '/link/:paramsName', component: MyComponent }