Skip to content

bug: Ionic life cycle hooks are not triggering in routed component #30644

Closed

Description

@Av1nag

Prerequisites

Ionic Framework Version

v8.x

Current Behavior

Image

"When I navigate from A(III) to B and then back to A(III), the Ionic lifecycle hooks inside A(III) are not being called, but the lifecycle hooks of Page A are being triggered.

Expected Behavior

Expecting Life cycle hooks in page A (III) to be triggered.

Steps to Reproduce

Note: Please keep browser console open to view the logs

  1. Go to page A (Now, in my demo application it will navigate to page A(III) by default in page A)
  2. Now from A(III), go to page B
  3. Now go back with browser back navigation to page A(III)

Now, If you see the browser you can only see page A ionViewWillEnter is only being triggered, but page A(III) ionViewWillEnter didn't triggered

Code Reproduction URL

https://stackblitz.com/github/Av1nag/ionic-routing-demo-app

Ionic Info

Ionic:

Ionic CLI : 7.2.0 (/Users/avinag/.nvm/versions/node/v18.20.5/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 8.7.2
@angular-devkit/build-angular : 20.1.6
@angular-devkit/schematics : 20.1.6
@angular/cli : 20.1.6
@ionic/angular-toolkit : 12.3.0

Utility:

cordova-res : 0.15.4
native-run : 2.0.1

System:

NodeJS : v18.20.5 (/Users/avinag/.nvm/versions/node/v18.20.5/bin/node)
npm : 10.9.1
OS : macOS Unknown

Additional Information

No response

Activity

  1. Av1nag commented on Aug 20, 2025

    @Av1nag
    Author

    Let me know if needed any clarification. I'm always here to help.

  2. Praise-99 commented on Aug 24, 2025

    @Praise-99

    We are experiencing the same issue throughout our entire application, and it is impacting major functionalities by causing frontend inconsistencies, as hooks are deeply integrated.

  3. Av1nag commented on Aug 28, 2025

    @Av1nag
    Author

    Hi @brandyscarney ,

    May I know any updates regarding this issue?

  4. thetaPC commented on Oct 16, 2026

    @thetaPC
    Contributor

    Thanks for the report, and sorry for the delay.

    Verified on 9.0.8, where this is fixed by #31532, released in v9.0.8. When you go from A(III) to B and back, the root ion-router-outlet transitions Page A, but the nested ion-router-outlet inside Page A never transitions, because A(III) was its active page the whole time. Ionic only fired lifecycle events on the page being transitioned, so A(III) received neither the enter events on the way back nor the leave events on the way out. From 9.0.8, the nested outlet forwards Page A's lifecycle events to its active page.

    If you can't move to 9.x yet, re-dispatch Page A's events onto the nested outlet's active page. This was verified on 8.8.19, and it is safe to keep after upgrading, since 9.0.8 detects the re-dispatch and does not fire the events twice:

    import { Component, ViewChild } from '@angular/core';
    import { IonRouterOutlet } from '@ionic/angular';
    
    @Component({
      selector: 'app-page-a',
      template: '<ion-router-outlet></ion-router-outlet>',
      standalone: false,
    })
    export class PageAComponent {
      @ViewChild(IonRouterOutlet) outlet!: IonRouterOutlet;
      private childLeft = false;
    
      ionViewWillEnter() { this.forward('ionViewWillEnter'); }
      ionViewDidEnter() { this.forward('ionViewDidEnter'); }
      ionViewWillLeave() { this.forward('ionViewWillLeave'); }
      ionViewDidLeave() { this.forward('ionViewDidLeave'); }
    
      private forward(eventName: string) {
        // On first entry the nested outlet already fired enter on its own page.
        if (eventName.endsWith('Enter') && !this.childLeft) {
          return;
        }
        this.outlet.getLastRouteView()?.element.dispatchEvent(new CustomEvent(eventName));
        if (eventName === 'ionViewDidLeave') {
          this.childLeft = true;
        }
        if (eventName === 'ionViewDidEnter') {
          this.childLeft = false;
        }
      }
    }

    The childLeft check matters: without it, A(III) gets its enter events twice the first time you open Page A.

    Closing this as completed, since the fix is in 9.0.8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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