如何在Angular 2中重新加载相同URL的组件?

Ani*_*ish 8 frontend typescript angular2-routing angular2-services angular

我试图通过使用router.navigate重新加载Angular 2中的相同URL,但它无法正常工作.url:http:// localhost:3000/landing 场景:我在http:// localhost:3000/landing,现在我正在更改页面中应该重新加载页面的特定参数.

代码:

let link = ['Landing'];
this.router.navigate(link);
Run Code Online (Sandbox Code Playgroud)

Pri*_*rya 15

导航到某个虚拟组件,然后导航到要重新加载的组件.//第二个参数_skipLocationChange = true以避免后退按钮中的url

this.router.navigateByUrl('/DummyComponent', true);
this.router.navigate(["Landing"]);
Run Code Online (Sandbox Code Playgroud)

  • @ trungk18我发现你需要传入一个对象,`this.router.navigateByUrl('/ Dummy',{skipLocationChange:true})`为我工作. (4认同)

小智 5

this.router.navigateByUrl('/DummyComponent', {skipLocationChange: true}).then(()=>
this.router.navigate(["Landing"]));
Run Code Online (Sandbox Code Playgroud)

  • 为什么要复制现有答案? (2认同)
  • @MaciejJureczko:看起来对我的答案不一样。 (2认同)