Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will Angular 2 child routes refresh the parent route

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?

like image 338
Mike Duister Avatar asked Jan 05 '23 18:01

Mike Duister


2 Answers

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

like image 125
Steveadoo Avatar answered Jan 21 '23 09:01

Steveadoo


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

like image 28
Renil Babu Avatar answered Jan 21 '23 09:01

Renil Babu