I find many examples where ActivatedRoute
Observables like params
or url
are subscribed but not unsubscribed.
constructor(private route: ActivatedRoute) {}
ngOnInit() {
this.route.params
// (+) converts string 'id' to a number
.switchMap((params: Params) => this.service.getHero(+params['id']))
.subscribe((hero: Hero) => this.hero = hero);
}
- Are the route objects and subscriptions destroyed automagically and newly created for every component creation?
- Do I have to care about unsubscribing from those
Observable
s? - If not, can you explain what happens with the tree of ActivatedRoute objects in
Router
.routerState
?
queryParams
subscription triggers one last time after that. – Daniel