首页  >  问答  >  正文

为什么在点击名称后,我无法将设置屏幕链接到登录/注册屏幕,而一直收到“undefined is not a function”的错误提示?

我想做一个简单的任务,就是从一个屏幕跳转到另一个屏幕,但无论我做什么都不起作用。我已经安装了 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 文件,但什么都不起作用。

P粉399090746P粉399090746420 天前668

全部回复(1)我来回复

  • P粉342101652

    P粉3421016522023-09-17 00:46:25

    你试过这个钩子吗

    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>
        );
      }

    回复
    0
  • 取消回复