永久违反:此导航器缺少导航道具。在react-navigation 3中,您必须直接设置应用容器

时间:2018-12-24 06:35:35

标签: javascript reactjs react-native

我正在尝试使用最新的react-navigation版本运行我的应用程序,但无法正常工作。还尝试使用此解决方案(Invariant Violation: The navigation prop is missing for this navigator),但没有解决方案。

错误消息

Invariant Violation: The navigation prop is missing for this navigator. In react-navigation 3 you must set up your app container directly. More info: https://reactnavigation.org/docs/en/app-containers.html

我的代码

App.js

import App from './app/index';
export default App;

index.js

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

import { SignedOut } from "./router";

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

router.js

import { createStackNavigator, createAppContainer } from "react-navigation";

import SignUp from "./screens/SignUp";
import SignIn from "./screens/SignIn";

export const SignedOut = createStackNavigator({
  SignUp: {
    screen: SignUp,
    navigationOptions: {
      title: "Sign Up"
    }
  },
  SignIn: {
    screen: SignIn,
    navigationOptions: {
      title: "Sign In"
    }
  }
});

参考:https://github.com/datomnurdin/auth-reactnative

2 个答案:

答案 0 :(得分:7)

react-navigation的先前版本中,App容器由create * Navigation方法提供。

react-navigation v3 中,您需要按照提及的here

手动添加应用容器
import { createStackNavigator, createAppContainer } from "react-navigation";

const SignedOutNavigator = createStackNavigator({
  SignUp: {
    screen: SignUp,
    navigationOptions: {
      title: "Sign Up"
    }
  },
  SignIn: {
    screen: SignIn,
    navigationOptions: {
      title: "Sign In"
    }
  }
});

export const SignedOut = createAppContainer(SignedOutNavigator); // Use this    

答案 1 :(得分:0)

在react-navigation v3中,您需要按以下链接中所述手动添加App Container https://reactnavigation.org/docs/en/app-containers.html