1constructor(private router: Router) { }
2
3public myMethodChangingQueryParams() {
4 const queryParams: Params = { myParam: 'myNewValue' };
5
6 this.router.navigate(
7 [],
8 {
9 relativeTo: activatedRoute,
10 queryParams: queryParams,
11 queryParamsHandling: 'merge', // remove to replace all query params by provided
12 });
13}
1// example url: details?id=2
2
3constructor(private activatedRoute: ActivatedRoute) {
4 this.activatedRoute.queryParams.subscribe(params => {
5 console.log(params); // Prints {id: "2"}
6 });
7}
8
1//in your HTML code :
2<a href="javascript:;" routerLink="/link/params">
3 My link
4</a>
5
6// app-routing.module.ts:
7//in your Routes array :
8{path: '/link/:paramsName', component: MyComponent }