Can `ion-menu` pop a page instead of pushing a page?

It seems like navigating between menu options using ion-menu will navigate forward (push the page to a stack). Is this intentional?

Is it possible to pop the page from the stack when navigating between menu options?

I realized this problem when I am navigating between two different pages using the ion-menu. It only runs each of the page’s ngOnInit() once, and since the page isn’t popped off, the ngOnInit() will not run again the next time.

I know a solution is to use ionViewWillEnter() or ionWillDidEnter(), but I was curious if there was still a way to pop a page instead of pushing a page to the stack.

I often think in terms of contracts when programming.

The contract of ngOnInit to me is: once it finishes, the component is ready to do its job. It may have allocated resources needed to do so. The corresponding contract of ngOnDestroy is that once it finishes, any resources allocated by ngOnInit have been released.

That’s all. Don’t use lifecycle events to manage anything else (like data freshness), and you no longer care how many times they’re called; only that the calls are balanced. Your design will be much more robust.

1 Like

Can you elaborate on data freshness?

I am trying to use lifecycle events (ionViewWillEnter and ionViewWillLeave) to subscribe and unsubscribe to a Subject.


Hopefully you can ensure that you don’t care how many times that subscribe/unsubscribe dance happens.

1 Like

Thank you for clarifying this for me! This makes me question my entire application now (hah!).