router.navigate with params angular 8 code example

Example 1: router navigate pass params

this.router.navigate(['action-selection'], { state: { example: 'bar' } });
...
constructor(private router: Router) {
  console.log(this.router.getCurrentNavigation().extras.state.example); 
  // should log out 'bar'
}

Example 2: angular routing url params

const appRoutes: Routes = [
  { path: 'crisis-center/:param1', component: CrisisListComponent },
  { path: 'hero/:param2',      component: HeroDetailComponent },
];

@NgModule({
  imports: [
    RouterModule.forRoot(
      appRoutes,
      { enableTracing: true } // <-- debugging purposes only
    )
    // other imports here
  ],
  ...
})
export class AppModule { }

Example 3: how to add changes every time you route navigate to page in angular

// Place import at the top
import { Router,NavigationStart} from '@angular/router';

//Place the code below inside your class
constructor(private router: Router){}

ngOnInit(){
   this.router.events.subscribe(event =>{
      if (event instanceof NavigationStart){
   		
      }
   })
}