强制调用 ngOnDestroy 和 ngOnInit

force to call ngOnDestroy and ngOnInit

我的组件没有被杀死以重新创建。

我转到“/tabs/home/order”,将 url 更改为“/tabs/home/wallet”后,订单页面不会被破坏,如果我返回 'tabs/home/order' 页面不调用 ngOnInit 有什么与模块或路由结构相关的吗?

什么触发了 angular 生命周期挂钩?

当 URL 发生变化时,我如何强制它终止并重新创建?

如果有什么与模块结构相关的,这个项目的模块结构是垃圾,home模块是延迟加载的,将Wallet和Order组件一起加载,这些组件的生命周期钩子没有调用

您描述的看似意外的行为是由于 Ionic。更具体地说,是由于 how Ionic deals with the life of a page.

When you navigate to a new page, Ionic will keep the old page in the existing DOM, but hide it from your view and transition the new page.

...

Because of this special handling, the ngOnInit and ngOnDestroy methods might not fire when you would usually think they should.

ngOnInit will only fire each time the page is freshly created, but not when navigated back to the page. For instance, navigating between each page in a tabs interface will only call each page's ngOnInit method once, but not on subsequent visits. ngOnDestroy will only fire when a page "popped".

在不太了解您的应用程序的情况下,我建议使用 Ionic Lifecycle events 而不是 Angular。听起来您可能只需将 ngOnInit 替换为 ionViewWillEnter 并将 ngOnDestroy 替换为 ionViewWillLeaveionViewDidLeave.

文档的下方是一些有用的内容 guidance for each lifecycle method