I want to fetch multiples ids which I am passing while routing in Angular using route.params. This is the route.ts
{path:'section/:id/:id', component: SubsectionsComponent}
And this is how I am routing from a component.ts
onSectionClick(id1, id2){
this.router.navigate(['/path/',id1,id2], {relativeTo:this.route})
}
And this is how I am fetching in the component where it routes.
constructor(private route: ActivateRoute){}
this.route.params.subscribe(
(route)=>{
console.log(route)
}
)
But it is only logging one id from the params.
You should use different names in your path. For example:
{path:'section/:id1/:id2', component: SubsectionsComponent}
And then it becomes pretty simple:
import { ActivatedRoute } from '@angular/router';
constructor(private route: ActivatedRoute) {
this.route.paramMap.subscribe( params => {
this.id_1 = params.get('id1');
this.id_2 = params.get('id2');
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With