Ionic-framework: Tabs component, ionViewWillEnter is not called on the active Tab, just the page holding the Tabs when doing nav back.

Created on 24 Dec 2016  路  9Comments  路  Source: ionic-team/ionic-framework

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

I'm submitting a ...
[x] bug report
[ ] feature request

Current behavior:
When navigating out of a page with a Tabs component and coming back, the ionViewWillEnter is called on the page holding the tabs component, but not on the active tab.

Expected behavior:
This event should probably be fired on the active tab.

Steps to reproduce:

  1. In a page with tabs, navigate out from the root like this
  2. this.app.getRootNav().push(SomeOtherPage);
  3. Navigate back to return to the tabs page
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.4
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 0.0.48
ios-deploy version: 1.8.6
ios-sim version: 5.0.8
OS: macOS Sierra
Node Version: v4.4.3
Xcode version: Xcode 8.2.1 Build version 8C1002

Sorry about not creating a Plunker, I am really in a rush this month.

Temporary work around
In the parent page that holds the Tabs component:

  isFirstLoad = true;
  ionViewDidEnter(){
    if(!this.isFirstLoad){
      if(this.tabs.getSelected()){
        let t = this.tabs.getSelected();
        let views = t.getViews();
        let v = views[views.length-1].instance;
        if(v.forceWillEnter){
          v.forceWillEnter();
        }
      } 
    } 
    this.isFirstLoad = false;
  }

In the child page (a Tab), I added this:

  forceWillEnter = () => {
    this.ionViewWillEnter();
  }
v3

Most helpful comment

Updating the issue.
version: 3.12.0

I'm navigating from ' TemplatePage' that is in tab navigation to another page using this.navCtrl.parent.parent.push('AddTemplate') and coming back to 'TemplatePage' with the default back button provided by ionic. I have a ionViewWillEnter() function in 'TemplatePage' with a log but that back action doesn't seem to trigger it. Upon changing tabs and coming back, it does fire.

All 9 comments

I can confirm that it's still an issue in Ionic 2.1.0.

I think this is not just the tabs but happening to any nested nav. The ionViewWillEnter is called on the page that is directly under the nav that is going through a transition, but if that page contained a child nav, its active page's ionViewWillEnter does not get called.

Updating the issue.
version: 3.12.0

I'm navigating from ' TemplatePage' that is in tab navigation to another page using this.navCtrl.parent.parent.push('AddTemplate') and coming back to 'TemplatePage' with the default back button provided by ionic. I have a ionViewWillEnter() function in 'TemplatePage' with a log but that back action doesn't seem to trigger it. Upon changing tabs and coming back, it does fire.

The same problem here.
ionViewWillEnter() not triggering in the tab page only in the main page containing all the tabs when coming back from another view push from the tab.

is this fixed?

I have the same problem here, but I can get a workaround using:

this.appCtrl.getActiveNav().parent.parent

@Component({
  selector: 'app-my-page',
  templateUrl: './my-page.page.html',
  styleUrls: ['./my-page.page.scss'],
})
export class MyPage {
 ionViewWillEnter() {
    console.log('ionViewWillEnter');
  }
}

to

import { ..., OnDestroy } from '@angular/core';

@Component({
  selector: 'app-my-page',
  templateUrl: './my-page.page.html',
  styleUrls: ['./my-page.page.scss'],
})
export class MyPage implements OnDestroy {
 ionViewWillEnter() {
    console.log('ionViewWillEnter');
  }

  ngOnDestroy(): void {
    console.log('ngOnDestroy');
  }
}

automatically "ionViewWillEnter" starts firing after leave TabsPage and enter on it again
working on Beta ionic 4

This issue has been automatically identified as an Ionic 3 issue. We recently moved Ionic 3 to its own repository. I am moving this issue to the repository for Ionic 3. Please track this issue over there.

If I've made a mistake, and if this issue is still relevant to Ionic 4, please let the Ionic Framework team know!

Thank you for using Ionic!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RobFerguson picture RobFerguson  路  3Comments

fdnhkj picture fdnhkj  路  3Comments

brandyscarney picture brandyscarney  路  3Comments

MrBokeh picture MrBokeh  路  3Comments

giammaleoni picture giammaleoni  路  3Comments