通过React导航将导航道具传入到功能组件屏幕可以通过以下步骤实现:
npm install @react-navigation/native
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();
function App() {
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Details" component={DetailsScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}
function HomeScreen({ navigation }) {
return (
<View>
<Text>Home Screen</Text>
<Button
title="Go to Details"
onPress={() => navigation.navigate('Details', { prop1: 'value1', prop2: 'value2' })}
/>
</View>
);
}
function DetailsScreen({ navigation }) {
const prop1 = navigation.getParam('prop1', 'default value');
const prop2 = navigation.getParam('prop2', 'default value');
return (
<View>
<Text>Details Screen</Text>
<Text>Prop1: {prop1}</Text>
<Text>Prop2: {prop2}</Text>
</View>
);
}
通过以上步骤,你可以通过React导航将导航道具传入到功能组件屏幕,并在目标屏幕中使用它们。请注意,这里的示例使用的是React Navigation库,你可以根据实际需求选择其他适合的导航库。
腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云