反应导航错误:此导航器缺少导航道具 [英] React Navigation Error: The navigation prop is missing for this navigator

查看:70
本文介绍了反应导航错误:此导航器缺少导航道具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经按照文档以及来自 stackoverflow 的解决方案进行操作,但我仍然不断收到错误消息.这是我的代码.我做错了什么?

I have followed the documentation and also the solutions from stackoverflow,I still keep getting the error. This is my code. What am I doing wrong?

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',
    },
});

推荐答案

你几乎是对的,只需在你的根组件中使用 Apps:

You're almost correct, just use Apps in you root component:

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

const Apps = createAppContainer(AppStackNavigator)

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

这篇关于反应导航错误:此导航器缺少导航道具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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