I got two pages:
- HomePage
- AboutPage
HomePage is the rootPage.
At startup HomePage#ionViewDidLoad
is called. I navigate from the HomePage to the AboutPage using the NavController:
navigateToAbout(): void {
this.navCtrl.push('AboutPage');
}
Everytime I navigate to the AboutPage, AboutPage#ionViewDidLoad
is called. If I navigate back to the HomePage with ion-navbar
, HomePage#ionViewDidLoad
is not called but if I use navCtrl.push('HomePage')
, HomePage#ionViewDidLoad
is called again.
Can someone explain, why ionViewDidLoad is called everytime if I use navCtrl.push(...)
. According to the Ionic NavController Doc the Pages should be cached and ionViewDidLoad should be called only once per Page:
View creation
By default, pages are cached and left in the DOM if they are navigated away from but still in the navigation stack (the exiting page on a push() for example). They are destroyed when removed from the navigation stack (on pop() or setRoot()).
ionViewDidLoad
Runs when the page has loaded. This event only happens once per page being created. If a page leaves but is cached, then this event will not fire again on a subsequent viewing. The ionViewDidLoad event is good place to put your setup code for the page.