我想做一個簡單的任務,就是從一個螢幕跳到另一個螢幕,但無論我做什麼都不起作用。我已經安裝了 react-navigation/stack 和 react-navigation/native-stack,但它們都不能與我現有的程式碼一起工作,是因為標籤頁嗎?
import { NavigationContainer } from '@react-navigation/native'; import { createStackNavigator } from '@react-navigation/stack'; import Tabs from './navigation/tabs'; import "react-native-url-polyfill/auto" import LogInSignUp from './SettingsScreen/LogInSignUp'; const Stack = createStackNavigator(); const App = () => { return ( <NavigationContainer> <Stack.Navigator screenOptions={{ headerShown: false }}> <Stack.Screen name="Home" options={{title: "Welcome"}} component={Tabs} /> <Stack.Screen name="Settings" component={Tabs} /> <Stack.Screen name = "LogInSignUp" component={LogInSignUp}/> </Stack.Navigator> </NavigationContainer> ); }; export default App; import { Text, StyleSheet, View, Button, } from "react-native"; import { StatusBar } from "expo-status-bar"; const Settings = (navigation) => { return ( <View style = {styles.container}> <Button title = "LogIn/SignUp" onPress={() => navigation.navigate("LogInSignUp")}></Button> </View> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', }, }) export default Settings import React from 'react' import { StackActions } from '@react-navigation/native'; const LogInSignUp = (navigation) => { return ( <div>LogInSignUp</div> ) } export default LogInSignUp
我嘗試尋找解釋這個問題的教程,他們所有的程式碼看起來都像我的程式碼,只是將名稱更換為我的 .js 文件,但什麼都不起作用。
你試過這個鉤子嗎
const navigation = useNavigation();