gpt4 book ai didi

javascript - 运行样板 react 导航应用程序时的 "undefined is not an object (evaluating ' Component.router ')"

转载 作者:行者123 更新时间:2023-12-02 23:32:47 24 4
gpt4 key购买 nike

我是 react 原生的新手,想尝试 react 导航。但是,当我尝试运行基本应用程序时,它给出了“未定义不是对象(评估“Component.router”)”错误。请帮忙

这是错误的屏幕截图 https://i.gyazo.com/fa89defeff8bef894f509f1511f9b1ae.png

除了安装之外,这是我在默认项目中唯一更改的内容 react 导航和 react native 手势处理程序

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

type Props = {};
export default class App extends Component<Props> {
render() {
return <AppNavigator/>;
}
}

class MainScreen extends Component{
render(){
return <Text>Hi</Text>
}
}

const AppNavigator = createAppContainer(SwitchNavigator);

const SwitchNavigator = createSwitchNavigator({
MainScreen : MainScreen,

});```


最佳答案

您的代码中有两个问题

(1) 您正尝试在声明之前访问 SwitchNavigator。(2) 您正在执行MainScreen : MainScreen,这会导致错误。

const SwitchNavigator = createSwitchNavigator({
MainScreen,
});

// optionally pass an object to your route, with screen, navigation options
const SwitchNavigator = createSwitchNavigator({
MainScreen: { screen: MainScreen },
});

const AppNavigator = createAppContainer(SwitchNavigator);

关于javascript - 运行样板 react 导航应用程序时的 "undefined is not an object (evaluating ' Component.router ')",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56423963/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com