I have a custom header for my stack navigation and I want to navigate to another page when I press on an image. But when I press the image I get an error undefined is not an object (evaluating _this.props.navigation.navigate')
In my App.js
const ProfileStackNavi = createStackNavigator({
stackAndTab:{
screen:ProfileTopTabNavigator,
navigationOptions: {
header: (
<MyPageTabBarHeader />
)
},
}
})
In my custom header class
export default class MyPageTabBarHeader extends Component {
constructor(props) {
super(props)
}
render() {
return(
<View style={{width:375,height:250, backgroundColor:'white'}}>
<TouchableOpacity onPress={()=>this.props.navigation.navigate('Register')}>
<Image
style={{width:23, height:23}}
source{require('../Components/Assets/register.png')} />
</TouchableOpacity>
</View>
</View>
)
};
}
I also tried <MyPageTabBarHeader navigation={this.props.navigation}/> but then it gives me the error undefined is not an object (evaluating this.props.navigation.navigate') the same error as previously but without an _ before this.
Edited
In my App.js I have createAppContainer. It looks like this:
const StartSwitchNavigator = createStackNavigator(
{
one:{
screen:screenOne,
},
{
two:{
screen:ProfileStackNavi,
}
);
const App = createAppContainer(StartSwitchNavigator);
export default App;
createAppContainer. Please show your whole code.