0
votes

Our app have multiple tabs, each tab contains a stack. We need to be able to navigate from a screen in a stack belonging to one tab to a specific screen in a stack belonging to another tab. This can be done like so navigation.navigate("tab2", {screen:"screen2"}).

We are using react-navigation version 5

Current Behavior

The problem is that if I have not navigated to the initial route for the destination stack(route) before, screen2 is now the only screen in the stack. I need somehow to always make sure that the screen specified in the initialRouteName is added to the stack first.

Expected Behavior

If you specify initialRouteName that route is always added as the first route in the stack, even if you navigate to a specific route defined in the stack.

Setting lazy=false, would solve the issue, but it's important to not initialise the "initial route screen" before actual navigating to a screen in the stack.

It might be that this is work as designed, but are there any way to achieve the behavior I expect then?

How to reproduce

The issue/problem can be reproduced in this snack Click the "Navigate to Screen2 on Tab 2" button on "tab1". Make sure you have not clicked on Tab2 before doing this. You are now navigated to Screen2 on Tab2 with no option to navigation to the screen specified in initialRouteName.

This is more of less a copy of this issue

1

1 Answers

0
votes

Found that you actual can navigate to a nested navigator and make sure the route specified in initialRouteName is the initial route. It can be done by specifying initial:false like so:

navigation.navigate("tab2", {screen:"screen2", initial: false})

Documentation can be found here