问题
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