I'm trying to do a simple task of jumping from one screen to another, but no matter what I do it doesn't work. I have installed react-navigation/stack and react-navigation/native-stack but neither of them work with my existing code, is it because of the tabs?
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
I tried looking up tutorials that explain this problem, all their code looks like my code, just changing the name to my .js file, but nothing works.
P粉3421016522023-09-17 00:46:25
Have you tried this hook
const navigation = useNavigation();
import {useNavigation} from '@react-navigation/native'; const Settings = () => { const navigation = useNavigation(); return ( <View style = {styles.container}> <Button title = "登录/注册" onPress={() => navigation.navigate("LogInSignUp")}></Button> </View> ); }