In ionic 3 there was lifecycle events like ionViewWillEnter
and ionViewWillLeave
. But in Ionic 4 this event must be replaced by Angular lifecycle events like ngOnInit
and ngOnDestroy
.
In my application I need to realize some given operations when the user enter or leaves a page. For example, if the user push another page (navigate forward in Ionic 4), the app whould execute ionViewWillLeave for the current page before the new page being pushed. If the user came back from a pushed page (navigate backward in Ionic 4) the app whould execute ionViewWillEnter for the previous page.
I tried to replace this events with ngOnInit and ngOnDestroy. But this events are called just one time each per page. For example, if I route to another page (navigate root in Ionic 4) and came back to the first page, the first page the ngOnInit and ngOnDestroy events will not be called again.
How can I call a event each time a user enter or leaves a page?