I have come across numerous instances where Observables related to ActivatedRoute
such as params
or url
are subscribed to 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);
}
- Do the route objects and subscriptions get destroyed automatically and recreated for every component creation?
- Is it necessary to manually unsubscribe from those
Observable
s? - If not, can you explain what happens with the tree of ActivatedRoute objects in
Router
.routerState
?