get parameters from url in angular 8 code example

Example 1: get url params angular

import { ActivatedRoute, Params } from '@angular/router';

@Component(...)
export class MyComponent implements OnInit {
   constructor (private activatedRoute: ActivatedRoute){}
   
   ngOnInit() {
    this.activatedRoute.params.subscribe((params: Params) => {
      if (params.myParam){
        // Do something
      }
    });
   }
}

Example 2: 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 }