首页 > 解决方案 > 切换导航器抛出错误“未定义不是对象('this.props')”

问题描述

我不知道该怎么做我已经尝试过堆栈导航器,道具也有同样的问题;/

进入屏幕

...
export default function App(props) {
    return (     
       <View style={{flex:1 , justifyContent:'center', alignItems:'center'}}> 
       <TouchableOpacity onPress={()=>{ 
         console.log(props)
       this.props.navigation.navigate('Home')
         //this.props.navigation.dispatch(SwitchActions.jumpTo('Home'))
         } } >
         <Text>switch test</Text>
       </TouchableOpacity>
       </View>   
    );
}...

导航

...
const SwitchNavigation = createStackNavigator({
 Enter:{screen : EnterScreen},
 Home:{ screen :HomeScreen}
})...
export default createAppContainer(SwitchNavigation);

应用程序

...
export default function App(props) {
  return (
       <NavigaitonScreens />
  );
}...

标签: react-nativereact-navigationreact-navigation-stack

解决方案


它与导航无关。

this功能组件中没有...

直接访问props喜欢props.navigation.navigate('Home')


推荐阅读