Search code examples
javascriptangularcomponentsangular2-routing

How can I reload the content of component in Angular 2?


At one moment of runtime my url looks like

http://localhost:4200/personal/51c50594-a95c-4a18-ac7b-b0521d67af96

I want to go to a page with only a different GUID and different content.

http://localhost:4200/personal/{otherGuid}

This is not working:

this.router.navigate(['/personal',new_ guid]);

How can I achieve this in angular 2 ?


Solution

  • try below,

     ....
      this.router.navigate(['personal', id]);
     ....
    
     constructor(route: ActivatedRoute, router: Router){
      this.route.params.subscribe(param => {
         // this will be fired when you change the guid,
         // use the new param to reload component..
      })
     }
    

    check this Plunker!!