我正在尝试使用最新的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"
}
}
});
答案 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