undefined 不是对象 options.routeGetIdList[action.payload.name]

问题描述 投票:0回答:3

导航到另一个页面时,会出现未定义的错误。通常没有进行任何更改。我删除了node_modules并重新安装。我重置了代码。我删除了该项目并重新启动。但没有解决。

TypeError:未定义不是对象(评估'options.routeGetIdList [action.payload.name]')

import { Button, View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

function HomeScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Home Screen</Text>
      <Button
        title="Go to Details"
        onPress={() => navigation.navigate('Home')}
      />
    </View>
  );
}

function DetailsScreen() {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>Details Screen</Text>
    </View>
  );
}

const Stack = createStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator initialRouteName="Home">
        <Stack.Screen name="Home" component={HomeScreen} />
        <Stack.Screen name="Details" component={DetailsScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}
export default App;
    "@react-native-async-storage/async-storage": "^1.13.2",
    "@react-native-community/clipboard": "^1.5.1",
    "@react-native-community/datetimepicker": "^3.0.9",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-firebase/admob": "^7.6.12",
    "@react-native-firebase/analytics": "^8.0.1",
    "@react-native-firebase/app": "^9.0.0",
    "@react-native-firebase/firestore": "^7.10.3",
    "@react-navigation/native": "^5.9.2",
    "@react-navigation/stack": "^5.12.6",
    "emoji-regex": "^9.2.1",
    "firebase": "^8.0.1",
    "grapheme-splitter": "^1.0.4",
    "react": "16.13.1",
    "react-native": "0.63.3",
    "react-native-gesture-handler": "^1.9.0",
    "react-native-onesignal": "^3.9.2",
    "react-native-raw-bottom-sheet": "^2.2.0",
    "react-native-reanimated": "^1.13.2",
    "react-native-safe-area-context": "^3.1.9",
    "react-native-screens": "^2.17.1",
    "react-native-snapchat-login": "^1.1.1",
    "react-native-vector-icons": "^7.1.0"
  },```
react-native react-navigation
3个回答
7
投票

前往

node_modules\@react-navigation\routers\src\StackRouter.tsx

并在第261行和第368行进行如下更改

options.routeGetIdList
options.routeNames

这解决了我的问题


5
投票

导航到另一个屏幕时,我也遇到了同样的错误,为了解决它,我刚刚将以下依赖项更新到最新版本:

@react-navigation/native

@react-navigation/stack

然后我清除了缓存并运行了项目:

cd android && gradlew clean && cd .. && react-native run-android

0
投票

我将

"@react-navigation/stack"
5.1.1
更新为
5.14.5
。这个问题对我来说完全消失了。只是 rm 模块、
run npm install
run android build

© www.soinside.com 2019 - 2024. All rights reserved.