【发布时间】:2020-04-17 20:36:17
【问题描述】:
如果之前我们以前做的其他屏幕没有发送任何内容,我想在路由参数中设置一个默认值 喜欢
let phot0 = this.props.navigation.getParam("photo","empty");
在 react Navigation 5.x 中做什么 我的代码是..(第 5 行有困难)
import React from "react";
import { StyleSheet, Text, View, Image, Button } from "react-native";
export default function Home({ route, navigation }) {
const { photo } = route.params;
return (
<View style={styles.container}>
<Image
resizeMode="center"
style={styles.imageHolder}
source={photo === "empty" ? require("../assets/email.png") : photo}
/>
<Button
title="take photo"
style={styles.button}
onPress={() => navigation.navigate("Camera")}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
imageHolder: {
alignSelf: "center",
},
button: {
margin: 20,
},
});
它还显示一些错误:未定义不是一个对象(评估'route.params.photo').. 我是否总是需要在发送屏幕中声明参数?
【问题讨论】:
标签: javascript react-native navigation react-native-navigation