In Ionic, pages are cached, and because of this, it is not always good to use angular lifecycle hooks
(ngOnInit, ngOnDestoy, ...). They just won't work, because the page is still on the stack.
With the help of Google and experiments, I learned 2 solutions (+ a little experimentation...).
Option A => "ng-hooks + ion-navigation"
You can use angular lifecycle hooks (ngOnInit, ngOnDestroy, ...),
but you need to navigate using navController.navigateRoot(...)
(why this method solves the problem-I do not know, it is magic)
Option B => "ng-navigation + ion-hooks"
You can apply angular routing using router.navigate(...)
,
but then you will need to use Ionic lifecycle hooks
(for example, ionViewDidEnter, ionViewDidLeave, ...)
This is certainly good, but I want more angular logic and less ionic logic.
question #1 => Which option do you use and why ?
And yet it seems to be different pages are cached in different ways.
One page when routed will simply change its position in the stack,
and the other will be removed from the stack (for some reason)
This is where the complete misunderstanding begins for me.
question #2 => How does it work (in simple words) ?
P.S.: thank you in advance for your answer, I am very interested to know )
question from:
https://stackoverflow.com/questions/65927878/how-to-make-optimal-routing-for-ionic-applications-what-life-cycle-methods-sho 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…