I am currently facing an issue where I need to navigate to the same component with different parameters. Although I can subscribe to the params through the ActivatedRoute, I'm encountering a problem when trying to call router.navigate
within the subscription.
In the sidemenu.component.ts file:
getTestValue(value:String){
this._router.navigate(['/example/home',value]);
}
In the home.component.ts file:
ngOnInit() {
this.route.params.subscribe(params => {
let id = params['id']; // (+) converts string 'id' to a number
console.log("params value"+id)// Even though I can retrieve this value, it does not update the component
this._router.navigate(['/example/home',id]); // This navigation is not triggering
}
I am aware of the option to use this
, but I prefer not to as using this
would trigger the ngOnInit
hook of the other component.
this._router.routeReuseStrategy.shouldReuseRoute = function() {
return false;
};
https://localhost:4200/example/home/123
https://localhost:4200/example/home/456 // The component is not updating in this case