简体   繁体   English

在路由特定屏幕后反复弹出“undefined is not an object (evaluating 'navigation.navigate')”

[英]Repeatedly popping "undefined is not an object (evaluating 'navigation.navigate')" after routing a particular screen

 const ResolvedPlaces = ({navigation}) => { return( <View style={Styles.headerWrapper}> <TouchableOpacity navigation={navigation} onPress={()=> navigation.navigate("ProfileScreen")} > <Text style={[Styles.header,{fontWeight:"bold"}]}>Resolved </Text> <Text style={Styles.header}> places</Text> </TouchableOpacity> </View> ) }

I have created a ResolvedPlaces function and gave a option to route to the profile screen.我创建了一个 ResolvedPlaces function 并提供了一个路由到配置文件屏幕的选项。 Also I've destructured the "navigation" in all format.我还解构了所有格式的“导航”。 But I continuously got this navgation.navigate as undefined object. the error message on the terminal但我不断得到这个 navgation.navigate as undefined object.终端上的错误信息

If ResolvedPlaces is not defined as a Screen in a react-native-navigation navigator , then the navigation prop will not be passed automatically to the component ResolvedPlaces .如果ResolvedPlaces未在react-native-navigation navigator中定义为Screen ,则navigation prop将不会自动传递给组件ResolvedPlaces

If ResolvedPlaces is nested inside a Screen that is defined in a Navigator , then you can use the navigation prop directly.如果ResolvedPlaces嵌套在Navigator中定义的Screen中,那么您可以直接使用navigation prop This could look as follows.这可能如下所示。

const SomeScreen = ({navigation}) => {

    const ResolvedPlaces = () => {
        return(
             <View style={Styles.headerWrapper}>
                <TouchableOpacity onPress={()=> navigation.navigate("ProfileScreen")} >
                <Text style={[Styles.header,{fontWeight:"bold"}]}>Resolved </Text> 
                <Text style={Styles.header}> places</Text>
                </TouchableOpacity>
            </View>
          )
       }
  
  return (
      <ResolvedPlaces />
  )
}

The component SomeScreen must be defined in a navigator, eg a Stack .组件SomeScreen必须在导航器中定义,例如Stack

If ResolvedPlaces is a component defined in its own file, then pass the navigation object as a prop from the parent that is defined as a screen.如果ResolvedPlaces是在其自己的文件中定义的组件,则将navigation object 作为来自定义为屏幕的父级的道具传递。

const SomeScreen = ({navigation}) => {
    return <ResolvedPlaces navigation={navigation} />
}

If this is not an option than you can still use the useNavigation hook as follows.如果这不是一个选项,那么您仍然可以按如下方式使用useNavigation挂钩。

const ResolvedPlaces = () => {

    const navigation = useNavigation()

    return (
        <View style={Styles.headerWrapper}>
                <TouchableOpacity onPress={()=> navigation.navigate("ProfileScreen")} >
                <Text style={[Styles.header,{fontWeight:"bold"}]}>Resolved </Text> 
                <Text style={Styles.header}> places</Text>
                </TouchableOpacity>
            </View>
    )
}

Remarks: I have removed the navigation prop from the TouchableOpacity since this prop does not exist for this component.备注:我已经从TouchableOpacity中删除了导航道具,因为该组件不存在该道具。 The basic react-native-navigation structure is documented here .基本的react-native-navigation结构在此处记录。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 undefined 不是一个对象(评估 &#39;navigation.navigate&#39;) - undefined is not an object (evaluating 'navigation.navigate') 未定义不是评估 navigation.navigate 的对象 - Getting undefined is not an object evaluating navigation.navigate undefined 不是 object(评估“navigation.navigate”)(设备) - undefined is not an object (evaluating 'navigation.navigate') (Device) ReactNative:未定义不是 object(评估“navigation.navigate”) - ReactNative: undefined is not an object (evaluating 'navigation.navigate') 例外:未定义不是 object(评估“navigation.navigate”) - Exception: undefined is not an object (evaluating 'navigation.navigate') 导航未定义 - 类型错误:未定义不是 object(评估“navigation.navigate”) - Navigation undefined - TypeError: undefined is not an object (evaluating 'navigation.navigate') TypeError: undefined is not an object (evaluating 'navigation.navigate') - 反应导航 - TypeError: undefined is not an object (evaluating 'navigation.navigate') - React Navigation 尝试从底部选项卡导航器的 header 访问屏幕时,未定义不是 object(评估“navigation.navigate”) - undefined is not an object (evaluating 'navigation.navigate') when trying to access a screen from the header of a bottom tab navigator React Native:未定义的错误消息不是对象(评估“navigation.navigate”) - React Native: Error Message undefined is not an object (evaluating 'navigation.navigate') React Native:未定义不是对象(评估“navigation.navigate”) - React Native : Undefined is not object (evaluating 'navigation.navigate')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM