如何重新加载 Angular 2 中组件的内容?

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

运行时 的某个时刻,我的 url 看起来像

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

我想转到一个只有不同 GUID 和不同内容的页面。

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

这不起作用:

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

如何在 angular 2 中实现此目的?

您可以导航到中间路线 /personal 并且在该页面中您可以获取参数并再次基于参数使用 switch case 导航到其他路线。在后半部分,如果您不想更改 url 栏中显示的路线,您可以使用此代码

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

skipLocationChange: true 在不将新状态推送到历史记录的情况下进行导航。

供您参考,您可以查看此 link

试试下面,

 ....
  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..
  })
 }

检查这个 Plunker!!