Ionic 4 ionViewWillLeave equivalent

Hi, what’s the equivalent to ionViewWillLeave in ionic v4?

1 Like

Which version are you using?

I’m using 4.1.2 and ionWillViewLeave works. It pops up after the other page has loaded though. Looks like a delay.

ionViewWillLeave(){
    console.log('Leaving Sign in Page');
  }

ionwillleave

It’s a bit confusing, but framework and CLI versions are totally unrelated. OP is asking about framework v4, and you’re talking about the CLI version.

First thing I would try is CanDeactivate.

In Ionic v4 ionViewWillLeave still exists

For reference: https://github.com/ionic-team/ionic/blob/37c9be7453ceb0e34b28f9c7338c77b90b626d19/core/src/index.ts

I think the confusion comes from the documentation which could be a bit misleading, according the amount of question about this subject. The only lifecycle, as far as I know, which doesn’t exist in v4 anymore is ionViewDidLoad, this has to be replaced with ngOnInit

5 Likes

thank you, you are right

What about Ionic 5? I’m having a hard time with the docs