I am making a react native project which got an error for no route found in stack navigator.First of all here is my code for navigation of my app.
const RootStack = createStackNavigator({
Splash : { screen: Splash },
ModelProfile: { screen: ModelProfile},
HomeModel: {screen: modeldrawerNavigator},
EnterOtp : { screen: EnterOtp},
OtpChangePassword : { screen: OtpChangePassword},
}, {
headerMode: 'none',
initialRouteName: 'Splash'
})
const AppNavigator = createAppContainer(RootStack)
export default AppNavigator;
Now the code for modelDrawerNavigator
is
const modeldrawerNavigator = createDrawerNavigator(
{
HomeScreen: { screen: homeStack},
EditProfile : { screen: profileStack},
BuyStar : { screen: StarStack},
Notifications : { screen: nStackmodel},
ResetPassword : { screen: ResetPassword},
},
{
initialRouteName: 'HomeScreen',
gesturesEnabled: true,
contentComponent: props => <DrawerModel {...props} />
},
);
And code for StarStack
is
const StarStack = createStackNavigator({
Buy : { screen: BuyStars},
PaymentMode : { screen: PaymentMode},
}, {
headerMode: 'none',
initialRouteName: 'Buy'
});
Now when navigating inside drawer i want to clear stack to position 0.
<TouchableOpacity
onPress={() => {
this.props.navigation.navigate('BuyStar');
const resetAction = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'Buy' })],
});
this.props.navigation.dispatch(resetAction);
}}
>
<Text style={styles.drawertext}>Buy Stars</Text>
</TouchableOpacity>
Above code is what produces an error that
No route defined for key 'Buy',Must be one of 'Splash','EnterOtp' etc.
I am stuck in this situation . Please help me to resolve this issue. Thanks in advance .