我正在编码产品详细信息,但无法使用params属性
无法读取未定义的属性“params”,您可以在此处看到我的代码
import React from 'react';
import {Image, Text, View} from 'react-native';
const ProductDetail = ({route, navigation}) => {
const productID = route.params;
return (
<View style={{flex: 1, justifyContent: 'center', alignItems: 'center'}}>
<Text>Product Detail</Text>
</View>
);
};
export default ProductDetail;
产品项目
const CardHeight = 220;
const ProductItem = ({list}) => {
const navigation = useNavigation();
return (
<ScrollView>
{list?.map((item, index) => {
return (
<TouchableOpacity
style={{
borderRadius: sizes.radius,
overflow: 'hidden',
flexDirection: 'row',
}}
onPress={() => {
navigation.navigate('ProductDetails'), {productID: index};
}}>
.....
);
};
export default ProductItem;
主导航器
const Stack = createStackNavigator();
const MainNavigator = () => {
return (
<NavigationContainer>
<StatusBar hidden />
<Stack.Navigator>
<Stack.Screen
name="Root"
component={TabDrawer}
options={{
headerShown: false,
useNativeDriver: true,
gestureEnabled: false,
}}
/>
<Stack.Screen
name="ProductDetails"
component={productDetailScreen}
options={{headerShown: false}}
/>
</Stack.Navigator>
</NavigationContainer>
);
};
export default MainNavigator;
我尝试按照参数传递到React导航路径,但没有成功productDetail
我不知道这个错误是从哪里来的,谁能给我具体解释一下
1条答案
按热度按时间qoefvg9y1#
将此
navigation.navigate('ProductDetails'), {productID: index};
替换为以下代码: