Ionic 4 ionViewWillLeave equivalent


#1

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


#2

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


#3

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.


#4

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


Ionic 4 - Listening to View Did Enter in Component
#5

thank you, you are right