Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48337

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 ?

Upvotes: 1

Views: 745

Answers (2)

Madhu Ranjan
Madhu Ranjan

Reputation: 17894

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!!

Upvotes: 3

Prathmesh Dali
Prathmesh Dali

Reputation: 2350

you can navigate to intermediate route /personal and in that page you can get the parameter and based on parameter again using switch case you can navigate to other route. In the latter part if you don't want to change the route displayed in url bar you can do this by using this code

this.router.navigate(['/view'], { skipLocationChange: true });

skipLocationChange: true Navigates without pushing a new state into history.

for your reference you can check this link

Upvotes: 0

Related Questions