get router params angular 8 code example
Example 1: angular router with wuery param
goProducts() {
this.router.navigate(['/products'], { queryParams: { order: 'popular' } });
}
http://localhost:4200/products?order=popular
constructor(private route: ActivatedRoute) { }
ngOnInit() {
this.route.queryParams
.filter(params => params.order)
.subscribe(params => {
console.log(params);
this.order = params.order;
console.log(this.order);
}
);
}
Example 2: home page routing in angular
const routes: Routes = [
{ path: 'home_page_path', component: HomePageComponent }
];
add this in app routing file
Example 3: router params angular
this.router.navigate(['/users/edit/', user.id]);