反复弹出“不确定的不是对象(评估' navigation.navigate;)"路由特定屏幕后
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>
)
}
我创建了一个分解空间函数,并提供了路由到配置文件屏幕的选项。另外,我以各种格式破坏了“导航”。但是我不断地得到了此导航。驱逐为未定义的对象。 终端上的错误消息
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
resolvedplaces
未定义为屏幕
在React-Native-Navigation Navigator
中,则navigation> navigation prop
将不会自动传递到组件resolvedplaces
。如果
resolvedplaces
嵌套在屏幕
中,该是在navigator
中定义的,则可以直接使用navigation prop
。这看起来如下。组件
somescreen
必须在导航器中定义,例如stack
。如果
resolvedplaces
是在其自己的文件中定义的组件,则将navigation
对象传递为从父母定义为屏幕的prop。如果这不是一个选项,则仍然可以使用
usenavigation
钩子如下。备注:我已经从
touchableOpacity
中删除了导航道具,因为此组件不存在此prop。基本React-Native-Navigation
结构记录在此处 。If
ResolvedPlaces
is not defined as aScreen
in areact-native-navigation navigator
, then thenavigation prop
will not be passed automatically to the componentResolvedPlaces
.If
ResolvedPlaces
is nested inside aScreen
that is defined in aNavigator
, then you can use thenavigation prop
directly. This could look as follows.The component
SomeScreen
must be defined in a navigator, e.g. aStack
.If
ResolvedPlaces
is a component defined in its own file, then pass thenavigation
object as a prop from the parent that is defined as a screen.If this is not an option than you can still use the
useNavigation
hook as follows.Remarks: I have removed the navigation prop from the
TouchableOpacity
since this prop does not exist for this component. The basicreact-native-navigation
structure is documented here.