JaRoMaster
JaRoMaster

Reputation: 179

How can I set a default screen for a nested Stack-Navigator in React-Native-Navigation v5?

I am using a stack navigator within a bottemtabbar and I want to set a default screen in the stack navigator. I'm using React-Native-Navigation v5, so I'll have to create the Navigator like this:

const Stack = createStackNavigator();

<Stack.Navigator
    screenOptions={{
      headerShown: false,
    }}>
    <Stack.Screen name="Feed" component={Feed} />
    <Stack.Screen name="Profile" component={Profile} />
    <Stack.Screen name="NewPost" component={NewPost} />
</Stack.Navigator>

I tried using initialRouteName, but when I open a screen in the Stack Navigator, then go back to anther Tab in my Tab Navigator and then go back to the tab with the Stack Navigator, it still shows the same Stack.Screen I viewed last (I want it to show a specific start screen each time).

Navigators:

Tab-Navigator:

Upvotes: 2

Views: 1182

Answers (2)

Tshediso Rathebe
Tshediso Rathebe

Reputation: 1

Maybe try setting the unmountOnBlur to true for your stack:

<Stack.Navigator screenOptions={{ unmountOnBlur: true }}>
    <Stack.Screen name="Screen1" component={Screen1} />
    <Stack.Screen name="Screen2" component={Screen2} />
</Stack.Navigator>

Upvotes: 0

Sam Dani
Sam Dani

Reputation: 124

Have you tried,

<Stack.Navigator initialRouteName="Feed"></Stack.Navigator>

Upvotes: 1

Related Questions