错误:路线“ Home”的组件必须是React组件

时间:2020-04-18 09:14:41

标签: react-native react-router react-navigation

我不断收到此错误。我已经浏览了与该错误有关的所有帖子,并尝试了所有方法来解决此错误,但是我仍然不知道为什么会收到此错误。

这是完整的错误声明:

Error: The component for route 'Home' must be a React component. For example:

import MyScreen from './MyScreen';
...
Home: MyScreen,
}

You can also use a navigator:

import MyNavigator from './MyNavigator';
...
Home: MyNavigator,
}

App.js:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import * as firebase from "firebase"
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';

import HomeScreen from './screens/HomeScreen'
import SignupScreen from './screens/SignupScreen'
import SigninScreen from './screens/SigninScreen'
import LoadingScreen from './screens/LoadingScreen'



const MainNavigator = createStackNavigator(
  {
    Home: { screen: HomeScreen },
    Loading: { screen: LoadingScreen },
    SignIn: { screen: SigninScreen },
    SignUp: { screen: SignupScreen }

  },
  {
    //launcher screen
    initialRouteName: "Loading"
  }
);

//create app container
const AppContainer = createAppContainer(MainNavigator);
export default class App extends React.Component {
  render() {
    return <AppContainer />;
  }
}

这是HomeScreen.js 我在这里没有做任何更改,这只是最低限度的样板代码

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class HomeScreen  extends React.Component {
render()
{  return (
    <View style={styles.container}>
      <Text>Open up App.js to start working on your app!</Text>
    </View>
  );
}
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

0 个答案:

没有答案