Will Angular 2 child routes refresh the parent route

流过昼夜 提交于 2019-12-13 13:28:45

问题


I have an application in which I route between children of a parent route in some situations. One will look like example.com/a/1/ another example.com/a/2/ will switching from 1 to 2 trigger a reload/render of the page a?

Like playing a video in a and have a routes outlet as sibling to that video, will this change of page trigger the video to reload?

If so, can this be prevented?


回答1:


No, it won't. The parent component will only be refreshed if you navigate away from it and then navigate to it again.




回答2:


I have got the solution:

constructor(private _router:Router,private _activatedRoute:ActivatedRoute){}
this._router.events.subscribe(event => {
  if (event instanceof NavigationEnd) { 
    // this._activatedRoute.snapshot is up to date
  }
});

Works like a charm

Credit: Angular Issue

Solution by @skreborn

Thanks



来源:https://stackoverflow.com/questions/41642727/will-angular-2-child-routes-refresh-the-parent-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!