0

I am trying to navigate to the same component, with different parameters. I am able to subscribe to the params through the activate Route, but I'm not able to call the router.navigate within the params from the subscription

sidemenu.component.ts

  getTestValue(value:String){
  this._router.navigate(['/example/home',value]);
 }  

home.component.ts

 ngOnInit() {
  this.route.params.subscribe(params => {
  let id = params['id']; // (+) converts string 'id' to a number
  console.log("params value"+id)// I am able to get this value but it is 
   nout ipdating component

   this._router.navigate(['/example/home',id]); // This is not getting called
   }

I know we have the option to use this, but I don't want to use this as this initiate the other component's ngOnInit hook.

   this._router.routeReuseStrategy.shouldReuseRoute = function() {
    return false;
   };

https://localhost:4200/example/home/123

https://localhost:4200/example/home/456 // This is not component is not updating

Subham
  • 420
  • 3
  • 11
  • 34
  • 1
    Possible duplicate of [Angular2 router - Navigate to the current page with different parameters](https://stackoverflow.com/questions/39613093/angular2-router-navigate-to-the-current-page-with-different-parameters) – Doguita Jul 04 '19 at 14:17
  • Please let me know how it is duplicate..when I have already tried the solution mentioned on the URL shared by you and still not able to get solution for my problem – Subham Jul 04 '19 at 15:34

1 Answers1

0

It's simple. Just use an object to map parameter to key-value.

this._router.navigate(['/example/home', { id: id }])
kuroneko0441
  • 415
  • 5
  • 14