开发者问题收集

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

2021-02-03
1356

导航到另一个页面时,它给出未定义的错误。通常没有做出任何更改。我删除了 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"
  },```
3个回答

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

然后在第 261 行和第 368 行进行如下更改

options.routeGetIdListoptions.routeNames

这解决了我的问题

Kavidu Aloka Kodikara
2021-05-03

当我导航到另一个屏幕时,发生了同样的错误,为了解决这个问题,我只需将以下依赖项更新到最新版本:

@react-navigation/native

@react-navigation/stack

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

cd android && gradlew clean && cd .. && react-native run-android
Kalebe Samuel
2021-03-13

我将 “@react-navigation/stack”5.1.1 更新到 5.14.5 。对我来说,问题已经完全解决。只需 rm 模块, 运行 npm install ,然后 运行 android build

Arsalan Ansari
2024-03-12