I create an Ionic 4 tab app.
Then generate a new page name second-page.
I use tab1 as main page, then add button navigate to second-page, add a back button at second-page to go back to main page, as below in html:
<ion-buttons slot="start">
<ion-back-button defaultHref="/"></ion-back-button>
</ion-buttons>
I add function ionViewDidEnter() for both pages for testing, as below:
ionViewDidEnter() {
console.log('ionViewDidEnter.....');
}
When the app start, the console shows that main page trigger the ionViewDidEnter function, navigate to second page, the ionViewDidEnter is triggered too. So far so good.
Then I click the back button, the ionViewDidEnter function at the main page is not triggered. Why?
Using router navigate at second-page ts file is not working too:
this.router.navigate(['tabs/tab1']);
It navigate to tab1, but the ionViewDidEnter did not triggered.
If navigate between tabs, from tab2 or tab3 to tab1, the function is working fine.
I know it’s ionic page lifecycle theory, but I just can’t figure it out.
Someone help. Thanks in advance.