I am trying to build my first React Native app and I am stuck with a navigation issue. My app has three screens in the Stack Navigator
Home
Login
User (User screen again is a Tab Navigator with three screens UserProfile, UserHome, UserSettings)
My Navigator
const Navigator = StackNavigator(
{
Home: {
screen: HomeScreen
},
Login: {
screen: LoginScreen,
},
User: {
screen: UserTabNavigator,
}
},{
initialRouteName: 'Home'
},
{
navigationOptions: () => ({
headerTitleStyle: {
fontWeight: 'normal',
},
}),
}
);
The initial route is Home so the app opens in Home screen, from there tapping on Login takes to Login screen
Now in my Login Component, after successful authentication I am redirecting to the User Screen.
When I get to the User Screen I see a back button and tapping it is taking me back to Login screen
I wanted to reset the navigation stack on successful authentication and set User screen as the root, so in the Login function I added
const resetAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({ routeName: 'User' })
]
});
this.props.navigation.dispatch(resetAction);
This works as I don't see the back button now, but after Login I see a weird animation of swipe back and briefly I see the Home screen and then redirected to User screen
What am I doing wrong?