'reset stack navigation when move from drawer navigation
I have a drawer navigation like that
const DrawerNavigatorRoutes = (props) => {
return (
<Drawer.Navigator>
<Drawer.Screen
name="homeScreenStack"
component={homeScreenStack}
/>
<Drawer.Screen
name="Profile"
component={profileScreenStack}
/>
</Drawer.Navigator>
);
};
When I click homeScreenStack the stack navigation is like that
const homeScreenStack = ({ navigation }) => {
return (
<Stack.Navigator initialRouteName="Dashboard">
<Stack.Screen
name="Dashboard"
component={Dashboard}
/>
<Stack.Screen
name="screen2"
component={screen2}
/>
....
</Stack.Navigator>
);
};
I also have some tab navigation in homeScreenStack So I want that when ever I click on homeScreenStack from drawer navigation Dashboard screen will open But in current scenario it didn't reset the stack. I am using react navigation 5
Solution 1:[1]
If I'm reading what you're asking correctly, you should be able to use the unmountOnBlur and set that to true on your drawer navigator to reset your stack. Then when you navigate back to your drawer navigator it will reset your stack navigator. So your code would look like:
const DrawerNavigatorRoutes = (props) => {
return (
<Drawer.Navigator
unmountOnBlur: true,
>
<Drawer.Screen
name="homeScreenStack"
component={homeScreenStack}
/>
<Drawer.Screen
name="Profile"
component={profileScreenStack}
/>
</Drawer.Navigator>
);
};
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ms217 |
