Tell us which versions you are using:
To persist dynamic scenes on navigation, I created a try/catch block with an Action.popTo method that will call Action.key whenever there are no scenes to popTo (using try/catch). I have used this up to RN 0.40/RNRF 0.38 and it was working as expected.
However, upon upgrading the project to the latest versions (RN 0.57/RNRF 4.0.6) the popTo method would now show a "cannot find routeName" type of warning and would no longer proceed to the catch block. With this, I cannot find an alternative anywhere to what I want to accomplish (popTo a scene if it exists, else push a new one)
Issues that come with minimal repro's are resolved much more quickly than issues where a maintainer has to reproduce themselves.
Yes, if Action methods could return a Promise we could popTo a fallback route incase the route we are trying to popTo is not available.
A Simple work around would be
let routeStack = Actions.state.routes
let routeNameToPopTo = routeStack.find(({routeName})=>routeName===yourRouteKeyToPopTo)
if(routeNameToPopTo)
Actions.popTo(routeNameToPopTo)
else // your alternative route to popTo
Hope this helps, I know it is a little cumbersome, but it provides more flexibility.
A Simple work around would be
- Access the navigation state using Actions.state
- get the route stack using Actions.state.routes
- find the routeName you want to popTo using the JS find function
- If your route exists then popTo that route else popTo an alternative
let routeStack = Actions.state.routes let routeNameToPopTo = routeStack.find(({routeName})=>routeName===yourRouteKeyToPopTo) if(routeNameToPopTo) Actions.popTo(routeNameToPopTo) else // your alternative route to popToHope this helps, I know it is a little cumbersome, but it provides more flexibility.
It's a great help.
Thanks for this! Will try it out.
@shubhang93 thanks, closing this
Most helpful comment
A Simple work around would be
Hope this helps, I know it is a little cumbersome, but it provides more flexibility.