ActivatedRoute in Angular stores routing information and can be used to extract routing parameters in the URL.
constructor(
private route: ActivatedRoute
){
}
ngOnInit(): void {
this.getUser();
}
getUser(): void {
const id = +this.route.snapshot.paramMap.get('id');
}
}
route.snapshot is a static snapshot of routing information, captured just after the component is created.
paramMap is a dictionary of route parameter values extracted from the URL. The value corresponding to id is the id of the user to be obtained. The routing parameter is always a string. The "+" operator in JavaScript will convert the string into a number.