I have screens in stacknavigator which are nested inside DrawerNavigator. I wanted to restart the screens in DrawerNavigator when clicked.
System flow Architecture:
App.js::
StackNavigator:
- Login.js
- ScreensSetup.js
ScreensSetup.js consists the following::
a. Stack screens as:
const FirstStackNavigator = createStackNavigator({
First: {
screen: Dashboard,
},
});
const SecondStackNavigator = createStackNavigator({
Second: {
screen: Workorders,
},
});
b. DrawerNavigator nested with above stacked screens as:
const DrawerNavigator = createDrawerNavigator({
Dashboard: {
screen: FirstStackNavigator,
},
Workorders: {
screen: SecondStackNavigator,
},
},
{
contentComponent: DrawerContent ,
initialRouteName: 'Dashboard',
});
I am able to navigate to "Workorders" from "ScreensSetup" by:
this.props.navigation.navigate('Workorders');
This works perfectly.
But I need to restart the screen. So, I used: For reseting ScreensSetup:
const navigateAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: "ScreensSetup" })],
});
this.props.navigation.dispatch(navigateAction);
This works perfectly.
For reseting Workorders:
const navigateAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: "Workorders" })],
});
this.props.navigation.dispatch(navigateAction);
This gives me error:
Error: Error: There is no route defined for key Workorders.
│ Must be one of: 'Login','ScreensSetup'
I simply wanted to reset the screen when clicked on menus on drawer naviagtor. I am completely messed up with this navigation. Any help would be appreciated. Thank You.