1import { ActivatedRoute } from '@angular/router';
2
3export class ExampleComponent implements OnInit {
4
5 constructor(private router: ActivatedRoute) { }
6
7 ngOnInit() {
8 this.router.queryParams.subscribe(res=>{
9 console.log(res) //will give query params as an object
10 })
11 }
12
13}
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//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 }