-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Description
Ionic version:
[] 4.x
[x] 5.x
I'm submitting a ...
[ ] bug report
[x] feature request
Hi, I was using ionic react for the past few years, and the only thing that i never understood well was the navigation.
I read the documentation several times and i think is not suited for all the cases.
In the present, ionic leave all your pages mounted, and there are 2 ways of remove it from the DOM programatically
1 - if you go from A -> B history.goBack()
-> A then B is removed from the DOM,
2 - if you go from A -> B navigate(C, "forward", "pop")
-> C then B is removed from the DOM (navigate
is from useIonRouter
or useContext(navContext)
With this aproaches you can remove 1 page from the DOM, but what if you want to remove a bunch of pages?
Well if you have something like this: HOME -> A -> B-> .... -> Z -> HOME and you want to unmount all the pages from A to Z because that was a flow that was already completed then u could do this:
1 - Put HOME in the main router outlet
2 - Put all the pages from A to Z in a nested router outlet
3 - When on Z use navigate(HOME, "forward", "pop")
and this will unmount the router oulet and with that all the pages in that outlet
This case is not documented and not explained at all, (in fact nothing in terms of mounted pages is documented, not even the hook and context used before)
And there are problems from this that are also not warned like the fact that if you use state
between pages and use useLocation
to consume that state you will have problems because of mounted pages:
if you go from A -> B with stateB
-> C with stateC
the page B that use useLocation
to get the stateB
will change to stateC
because you are now in C but B is mounted so the app may crash, in a case when you were doing stateB.person.dni
on B but you are now in page C with stateC
that has not the object person, then B will crash for doing dni of undefined
Also the strategy of nested IonRouterOutles is not the silver bullet, because you will have cases like
TABS -> HOME -> A -> ... -> X -> Z -> HOME -> TABS
in wich if you wanna go back from HOME -> TABS you will need to do something in HOME like put a backButton listener to do navigate(TABS, "forward", "pop") because the hardware back button will do a goBack that will go to page X (because Z was not only unmounted but also popped from the history, and not only this, you also will notice of wrong transition between routerOutlets)
With all that, it will be EXTREMELY nice if you come with a more detailed and in deep documentation of the react navigation and how to use it properly.
I have +4 years of experience with ionic and the navigation always is a major problem, because is one of the most important thing o an app
Thanks and I hope someone read this!
Cheers.
Ionic info:
Ionic:
Ionic CLI : 6.19.0
Ionic Framework : @ionic/react 5.9.1
Capacitor:
Capacitor CLI : 4.1.0
@capacitor/android : 4.1.0
@capacitor/core : 4.1.0
@capacitor/ios : 4.1.0
Utility:
cordova-res : 0.15.1
native-run : 1.7.0
System:
NodeJS : v14.17.0
npm : 6.14.13
OS : Windows 10