我放弃了 2 个选项。首先你回答你的问题。长篇文章展示了如何使用 React Navigation 进行良好实践。
简答
navigation.navigate('OtherScreens', { screen: 'OtherScreen1' });
长答案https://snack.expo.io/@anthowm/navigators
function Feed() {
const navigation = useNavigation();
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Feed!</Text>
<Button onPress={() => {navigation.navigate('OtherScreens', { screen: 'OtherScreen1' });}} title='press'></Button>
</View>
);
}
function Messages() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Messages!</Text>
</View>
);
}
function Profile() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Profile!</Text>
</View>
);
}
function Settings() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Settings!</Text>
</View>
);
}
function OtherScreen1() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>OtherScreen1!</Text>
</View>
);
}
function OtherScreen2() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>OtherScreen2!</Text>
</View>
);
}
const Tab = createBottomTabNavigator();
const Stack = createStackNavigator();
function Home() {
return (
<Tab.Navigator>
<Tab.Screen name="Feed" component={Feed} />
<Tab.Screen name="Messages" component={Messages} />
</Tab.Navigator>
);
}
function MainStack() {
return (
<Stack.Navigator>
<Stack.Screen name="Home" component={Home} />
<Stack.Screen name="Profile" component={ProfileStack} />
<Stack.Screen name="OtherScreens" component={OtherScreensStack} />
</Stack.Navigator>
);
}
function ProfileStack() {
return (
<Stack.Navigator>
<Stack.Screen name="Profile" component={Profile} />
<Stack.Screen name="Settings" component={Settings} />
</Stack.Navigator>
);
}
function OtherScreensStack() {
return (
<Stack.Navigator>
<Stack.Screen name="OtherScreen1" component={OtherScreen1} />
<Stack.Screen name="OtherScreen2" component={OtherScreen2} />
</Stack.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<MainStack />
</NavigationContainer>
);
}