I want to navigate back from DrawerNav to Login. Using alert('Alert') inside the function is OK.
I have a StackNavigator with Login and DrawerNav
const MyStackNavigator = StackNavigator({
Login : { screen : Login },
DrawerNav : { screen : DrawerNav }
}, {
navigationOptions : { header : false }
}
);
From Login i can navigate to my main screen DrawerNav using
_login = () => {
this.props.navigation.navigate('DrawerNav');
}
Inside the DrawerNav is a DrawerNavigator (obviously)
const MyDrawerNavigator = DrawerNavigator({
... screens ...
}, {
initialRouteName : '',
contentComponent : CustomContent,
drawerOpenRoute : 'DrawerOpen',
drawerCloseRoute : 'DrawerClose',
drawerToggleRoute : 'DrawerToggle'
}
);
const CustomContent = (props) => (
<View>
<DrawerItems {...props} />
<TouchableOpacity
onPress={ this._logout }>
<Text style={ styles.logout }>Logout</Text>
</TouchableOpacity>
</View>
)
As you can see, the logout is not part of the menu but inside the Drawer
_logout = () => {
this.props.navigation.navigate('Login');
}
This gives me an error
undefined is not an object (evaluating '_this.props.navigation')