反应本机导航类型错误:未定义不是对象(评估'Object.keys(routeConfigs)') [英] React Native navigation TypeError: undefined is not an object (evaluating 'Object.keys(routeConfigs)')

查看:45
本文介绍了反应本机导航类型错误:未定义不是对象(评估'Object.keys(routeConfigs)')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 App.js 文件中有以下代码:-

I have the following code in App.js file:-

import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import { NavigationContainer} from "react-navigation";


const Home = ({ navigation }) => {
  return (
      <View>
        <Text>This is Home page!</Text>
      </View>
  )
}

const Stack = createStackNavigator();

function MyStack() {
  return (
      <Stack.Navigator>
        <Stack.Screen name="Home" component={Home} />
      </Stack.Navigator>
  );
}
 export default function App() {
   return (
       <NavigationContainer>
         <MyStack />
       </NavigationContainer>
   );
}

我在此页面上遵循了相同的说明:-

I followed the same instruction on this page:- https://reactnavigation.org/docs/stack-navigator/ But it gave an error

推荐答案

我按照版本 4 文档修复了该问题问题是,当我按照以下命令安装 react-navigation 包时:-

I fixed the issue by following the version 4 documentation The problem is that when i installed the react-navigation package by following these commands:-

yarn add @react-navigation/native

我假设默认情况下,如果我安装任何包而没有定义特定版本,它假设安装该包的最新当前版本(v5),默认情况下我遵循版本 5 的包文档.当我检查已安装的软件包版本时,我注意到版本 4 没有安装 5 .

I assumed by default if i install any package without defining a specific version, it suppose to install the latest current version of that package which is (v5) any by default i followed the package documentation for the version 5 . and when i checked the installed package version i noticed that the version 4 is installed no 5 .

现在我使用了第 4 版堆栈创建语法:-

Now i used the version 4 stack creating syntax :-

const navigator = createStackNavigator({
    Home:Home,
},
    {
        initialRouteName: 'Home'
    });
export default createAppContainer(navigator);

现在一切正常

这里是

V5 https://reactnavigation.org/docs/hello-react-navigation

V4 https://reactnavigation.org/docs/4.x/getting-开始

这篇关于反应本机导航类型错误:未定义不是对象(评估'Object.keys(routeConfigs)')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆