ionViewDidEnter is not invoked on leaving a pushed page

I’ve found a common solution, which is working for me as it should.

My root page is a tab-page, which includes five child pages. Within the five child pages, I push new pages on the highest parent level of the tab-page navController (this.navCtrl.parent.parent) to overlay the tab-page footer and have only the pushed page on the full screen.

That means, on every child page of the tab-page I’m working with this.navCtrl.parent.parent and I push pages like this:

this.navCtrl.parent.parent.push(...);

Due to the fact that a child pages IonViewDidEnter will be only fired, when it’s getting the active page, and not, after a pushed page .pop()'s we need to set a custom listener on viewDidEnter on the highest parent of the navCtrl (this.navCtrl.parent.parent). Something like this:

// Constructor of a child-page within the tab-pages
constructor(
	private test: Test,
	private foo: Bar
) {	
	// Little workaround to observe the `viewDidEnter` event from the 'this.navCtrl.parent.parent'
	this.navCtrl.parent.parent.viewDidEnter.subscribe((data: any) => {

		// Here you should be able to detect, if a child page get's active again, after another page was 'push()'ed.
		
		// You can check the retrieved data, to make it only work, if a specific page firess `viewDidEnter`
		console.log(data);

		this.refreshMyData();
		return;
	});
	return;
}

Hope it helps someone :-).

Cheers
Unkn0wn0x

2 Likes