React导航错误:此导航器缺少导航道具



我遵循文档以及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',
    },
});

您几乎是正确的,只需在root组件中使用应用程序:

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

相关内容

  • 没有找到相关文章

最新更新