取消订阅 queryparammap - 这有必要吗?

Unsubscribing from queryparammap - has this become necessary?

谷歌搜索 angular 的 ActivatedRoute 中的订阅管理得到了对 angular 文档的相同引用,其中声明您不必取消订阅 ActivatedRoute observables 因为它被路由器干净地拆除了。

但是,当自己查看文档时,它不再有此部分解释这一点。我尝试使用 finalize 来测试当组件被销毁时 observable 是否已完成:

this.activatedRoute.queryParamMap.pipe(finalize(() => console.log('done')).subscribe()

但是,从未调用控制台日志。我不确定这是因为 Observable 直接被摧毁了,还是只是保持打开状态。

是否有必要管理 ActivatedRoute 的订阅生命周期?

Each ActivatedRoute is bound to a routed component and when a route changes occurs, the current component being displayed is going to be destroyed, as well as its bound ActivatedRoute, so that's why you won't get a complete notification.

我在这篇 answer.

中详细阐述了它