1import {Router, ActivatedRoute, Params} from '@angular/router';
2import {OnInit, Component} from '@angular/core';
3
4@Component({...})
5export class MyComponent implements OnInit {
6
7 constructor(private activatedRoute: ActivatedRoute) {}
8
9 ngOnInit() {
10 // Note: Below 'queryParams' can be replaced with 'params' depending on your requirements
11 this.activatedRoute.queryParams.subscribe(params => {
12 const userId = params['userId'];
13 console.log(userId);
14 });
15 }
16
17}
1const product = urlParams.get('product')
2console.log(product);
3// shirt
4
5const color = urlParams.get('color')
6console.log(color);
7// blue
8
9const newUser = urlParams.get('newuser')
10console.log(newUser);
11// empty string
12