ionic-framework: bug: Nested IonRouterOutlet prevents component unmount
Bug Report
Ionic version:
5.0.1
Here is a repo with a minimal code to reproduce the bug: https://github.com/OoDeLally/ionic-nested-router-outlet-bug
Ionic info:
▶ ionic info
Ionic:
Ionic CLI : 5.4.16 (/home/pascal/.nvm/versions/node/v8.16.0/lib/node_modules/ionic)
Ionic Framework : @ionic/react 5.0.1
Utility:
cordova-res : not installed
native-run (update available: 0.3.0) : 0.2.9
System:
NodeJS : v8.16.0 (/home/pascal/.nvm/versions/node/v8.16.0/bin/node)
npm : 6.4.1
OS : Linux 4.15
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 8
- Comments: 30 (2 by maintainers)
Hello all,
I’m looking into this now, hope to have something to report on soon.
Anybody? This is a huge blocker for me
This is a huge blocker for me.
Hi All,
We have a dev release that provides better support for nested IonRouterOutlet components. There is a new prop on IonRouterOutlet that lets the router know it is a nested outlet to better perform the transition.
If your’e outlet is a nested outlet directly rendered by a Route in a parent outlet, then use the
ionPageprop on the IonRouterOutlet. Here is an example:App.tsx:
Sub1Outlet.tsx:
Sub2Outlet.tsx:
If you can, could you try to install it and let us know if it fixes the issue and if you run into any others? To install it run:
npm i @ionic/react@5.3.0-dev.202006222125.df37029 @ionic/react-router@5.3.0-dev.202006222125.df37029If all goes good this should be available in the next Ionic release.
Thanks!
It seems to me that Ionic just don’t deal with these issues.
In case of Vue framework, adding key attribute to “ion-router-outlet” resolved it for me
<ion-router-outlet id="main-content" :key="route.fullPath" ></ion-router-outlet>I first noticed this issue with a single layer of routes (no nesting) and an apollo query with the
no-cacheoption. Desired outcome, anytime i navigate to page X it would re-query the backend. I was surprised to see it not making the query a 2nd or more times. After days of searching git issues and changing versions of apollo/ionic etc i tried a useEffect callback function and noticed it wasn’t working which is what apollo’s useQuery uses to refetch.All that to say i think the not unmounting components on
forwardandnonedirections is a premature optimization. What if we made this an option on the Route? <Route cache={true}/> or something? This way the dev has to opt into the optimization and isn’t surprised by it. [If enough ppl +1s this idea i can start working on a PR]No, God, please, no 😃 Try this https://github.com/ionic-team/ionic/issues/20707#issuecomment-598806108
I found a workaround.
You can set an
idto the<IonPage>. When you click the header button, the app will go back and remove your page from the DOM.This is to force unmount the page, and because this page is no longer on the DOM it cannot execute its life cycles.
This is my helper function
This is my page
This is my custom header
Hope this helps
The issue continues. There is no need for nested ionrouteroutlet. The problem occurs at only one router. https://github.com/ionic-team/ionic-framework/issues/20298 https://github.com/ionic-team/ionic/issues/20844 https://github.com/ionic-team/ionic/issues/20597
It didn’t unmount the component for me. For now I will stick with
routerDirection="back". Although it’s not correct, it’s working the way I needHi, any news of this? I’ve tried to investigate checking the source code, but it seems beyond my level of understanding.