ionic-framework: Lifecycle events potentially not being triggered when using side menu

Ionic version: [ ] 1.x [x] 2.x

I’m submitting a … [x] bug report [ ] feature request [ ] support request

Current behavior: The ionViewWillLeave and ionViewDidLeave lifecycle events do not fire when navigating using the side menu.

Expected behavior: The events to be fired when navigating with the side menu.

Steps to reproduce: Download a fresh copy of the ionic conference app. Add the below code to schedule.ts. Note that these events are only being picked up when navigating with the tabs, they don’t get picked up when navigating with the side menu.

Related code:

  ionViewWillLeave () {
    console.log( 'view will leave' );
  }

  ionViewDidLeave () {
    console.log( 'view did leave' );
  }

Other information:

Ionic info:

Cordova CLI: 6.4.0 
Ionic Framework Version: 2.0.0-rc.4
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.47
ios-deploy version: 1.9.0 
ios-sim version: 5.0.11 
OS: macOS Sierra
Node Version: v7.0.0
Xcode version: Xcode 8.1 Build version 8B62

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 24 (19 by maintainers)

Most upvoted comments

Tested with the latest nightly (2.0.0-rc.4-201701101946), same behavior.

To summarize:

Lifecycle hook Tabs Side menu
ionViewDidLoad
ionViewWillEnter
ionViewDidEnter
ionViewWillLeave
ionViewDidLeave
ionViewWillUnload
ionViewCanEnter
ionViewCanLeave

Hello @jsayol sorry for the lack of a reply on this lately, been very busy here at Ionic. So for this comment https://github.com/driftyco/ionic/issues/9951#issuecomment-272035391: ionViewCanEnter is only firing once because the tabs view is actually only loading in once. ionViewDidLoad also only fires once for the first tab because of the same reason. ionViewCanLeave also only fires once because the tabs view does not actually leave. By setting root your reloading the nav stack which then makes it fire because the earlier nav stack is actually leaving at that time. I agree with you that renaming them might be a good solution here but as it sits now the lifecycle events are working as they should. Also, for the record, the way navigation happens in the conference app is a little weird compared to 90% of the ionic apps out there, which is one of the reasons that the way lifecycle events work in the conf app is a little confusing at first. Because the lifecycle events are working as they should I am going to close this issue for now, but i definitely think the discussion should continue on renaming some of the lifecycle events in the other issue you opened. Thanks for using Ionic!

Back to the original issue, the alternative would be to trigger the relevant lifecycle hooks on any child views and not just on the one being acted upon.

For example, if an ionViewWillLeave triggers for TabsPage then it should also trigger for the page of the currently selected tab. I’m not sure if this could cause any problems, though, but it’s worth exploring.

@jsayol ahh just ahead of me in typing that haha (: So you are 100% correct here. Honestly, this is kinda confusing though so im checking with the rest of the team on exactly what the behavior of the lifecycle events should be in this situation. In a literal sense, they are working exactly like they should, but since its slightly confusing at first i want to make sure this is how we want them working. Again, just want to say thanks for testing all this with me and standing all my questions!