反应导航错误:此导航器缺少导航道具

时间:2019-03-11 00:53:52

标签: javascript reactjs react-native

我已经遵循了文档以及stackoverflow的解决方案,但我仍然不断收到错误消息。 这是我的代码。我在做什么错了?

import React, { Component } from 'react';
import { Button, View, Text, StyleSheet } from 'react-native';
import { createStackNavigator,createAppContainer } from 'react-navigation';
import MainScreen from './components/MainScreen';


export default class App extends React.Component {
    render() {
        return <AppStackNavigator />;
    }
}
const AppStackNavigator = createStackNavigator({
    Main: {
        screen: MainScreen,
    },
});

export const Apps = createAppContainer(AppStackNavigator)


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

1 个答案:

答案 0 :(得分:1)

您几乎是正确的,只需在根组件中使用Apps:

const AppStackNavigator = createStackNavigator({
    Main: {
        screen: MainScreen,
    },
});

const Apps = createAppContainer(AppStackNavigator)

export default class App extends React.Component {
    render() {
        return <Apps />;
    }
}