Skip to content

bug: Vue lifecycle hooks are only called in top level component #27026

@aparajita

Description

@aparajita

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

The Vue lifecycle hooks (onIonViewWillEnter, etc.) are only called in the top level component for any given page, whether or not that component's template contains IonPage. Lifecycle hooks will never be called in a child component, even if their template contains IonPage.

Expected Behavior

The documentation is silent on the restriction imposed by the current behavior. I expected the lifecycle hooks to work from anywhere within the component hierarchy.

Steps to Reproduce

  1. Open the stackblitz project.
  2. Note that in Tab one, the lifecycle hooks are in a child component and are not called; no alert appears.
  3. Click on Tab two. An alert appears for onIonViewWillEnter and onIonViewDidEnter, since they are called from within the top level component.

Code Reproduction URL

https://stackblitz.com/edit/angular-wmuse1?file=src/views/TabTwo.vue

Ionic Info

Run from StackBlitz project:

Ionic:

Ionic CLI : 6.20.9

Utility:

cordova-res : not installed globally
native-run : not installed globally

System:

NodeJS : v16.14.2
npm : 7.17.0
OS : Linux 5.0

Additional Information

I am not the only person who has run into this issue. If it is not feasible to make the lifecycle hooks work in a child component, the documentation should be updated to clearly state the restriction that they only work within the top level component of a view.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions