ionic-framework: [ionic 4] ionViewWillEnter only triggers once.
Bug Report
Ionic Info
Run ionic info from a terminal/cmd prompt and paste the output below.
Ionic:
ionic (Ionic CLI) : 4.0.5
Ionic Framework : @ionic/angular 4.0.0-beta.3
@angular-devkit/core : 0.7.2
@angular-devkit/schematics : 0.7.2
@angular/cli : 6.1.2
@ionic/ng-toolkit : 1.0.5
@ionic/schematics-angular : 1.0.4
Cordova:
cordova (Cordova CLI) : 8.0.0
Cordova Platforms : android 7.0.0, ios 4.5.5
System:
Android SDK Tools : 25.2.5
ios-deploy : 1.9.2
ios-sim : 6.1.2
NodeJS : v7.4.0 (/usr/local/bin/node)
npm : 4.0.5
OS : macOS High Sierra
Xcode : Xcode 9.4.1 Build version 9F2000
Environment:
ANDROID_HOME : /usr/local/Cellar/android-sdk/24.4.1_1
Describe the Bug
The ionViewWillEnter lifecycle (if its still called that) only triggers once. In ionic 3 the ionViewWillEnter triggered every time you navigated to the view. Now it only triggers the first time.
Steps to Reproduce Steps to reproduce the behavior:
- Add
ionViewWillEnterto your view
public ionViewWillEnter(): void {
console.log('hi');
}
- Navigate to the page
- Navigate to a different page
- Navigate again to the page with the
ionViewWillEnter
Expected Behavior
Expect the console.log('hi') to be logged every time I navigate to the view.
Additional Context
Note that I use tabs. Is there perphaps a Angular lifecycle which replaced ionViewWillEnter?
-- tabs
-- View 1 (with ionViewWillEnter)
-- View 2
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 14
- Comments: 48 (12 by maintainers)
In the meanwhile, as a workaround, I am using below setup to mock the
ionViewWillEnterevent. Note that the url in the subscription should be that of the current page.Custom interface
Hi guys,
any thing on this from the Ionic team yet?
How is it a duplicate of #14566 ? You can have lifecycle hooks without lazy-loading. Lifecyle hooks are supposed to be about navigation and wich page/component is focused, not about how and when it is loaded.
I’m not talking from a technical point of view (I don’t know how Ionic handle it internally) but from a functionnal point of view.
It’s closed because it’s a duplciate of #14566 (it makes no sense to have different issues open for the same topic)
I’ve implemented the following more generic workaround:
This class can then used as follows:
@paulstelzer Can you at least tell us if it’s planned to change the lifecycle behaviours for tabs ?
With your post medium (thanks for the clarification btw) the current behaviour is not a bug. But at the same time it’s not really the behaviour wanted nor expected by the users (especially regaring the names of the lifecycle hooks). If nothing is planned for tabs & lifecycle hooks, we will be forced to keep the ugly hack based on routes to know is a user enters/leaves a tab.
At least this issue should not be closed but transformed instead in a feature request.
Any update on when this is going to be fixed from the ionic team
Worst of all, if you have this kind of routing :
Navigating between
homeandotherPagethe lifecycle events won’t be triggered onhome(at least forionViewDidEnterorionViewWillLeave, haven’t tested the other). They are triggered correctly onotherPagecomponent thought.ionViewWillEnter is triggering when navigating between tabs. It doesn’t trigger when navigating back from different page to tab.
It doesn’t work with RC0.
This also happens when using goRoot dynamically(programmatically). It wil not fire ionViewWillEnter…
Same issue here. Lifecycle functions work if your page is not inside a tab (or if you change page inside the same tab) but not when switching between two different tabs.
IonViewWillEnter only triggers when navigation is within the same tab. If you navigate to a different page in tab 1 and then back IonViewWillEnter is fired but it isn’t fired on switching tabs
On Thu, Dec 27, 2018, 4:36 PM RZR666 <notifications@github.com wrote:
What exactly is the issue?
If it’s the tab issue, then please follow https://github.com/ionic-team/ionic/issues/14566#issuecomment-416243089
If you wonder about life cycles, please read here -> https://medium.com/@paulstelzer/ionic-4-and-the-lifecycle-hooks-4fe9eabb2864
I make it work.
Be sure that if you navigate to one page in the tab, that page have the same outlet. Also with that if the navigation you don’t do it properly it will go back but will not enter in the ionViewWillEnter. For html with ionic component: href=“/main/tabs/(home:sneaker/{{sneaker.$key}})” routerDirection=“forward” Following the outlet: { path: ‘sneaker/:id’, outlet: ‘home’, component: SneakerPage },
Bump, 4.0.0-beta-17 release still has this critical issue 😦
It has been a while since the first post. Can’t believe that nobody has fixed this bug.
It might be that you redirect in your routes. So I had to check for the url in the subscription:
Instead of:
same here, fix it please.
same here
Same issue with
ionViewDidEnter.Concerning
ionViewWillLeave:tabs/(home:home)totabs/(browse:browse)->ionViewWillLeaveis never triggered Switching between pages (same router outlet) E.g.tabs/(home:home)totabs(home:contact)->ionViewWillEnteris triggered every time.