当我尝试启动我的 react native 应用程序时收到此消息。通常这种格式适用于其他多屏幕导航,但在这种情况下不知何故不起作用。
这是错误:
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
这是我的应用程序格式:
import React, {Component} from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createStackNavigator } from 'react-navigation';
import Login from './view/login.js'
import SignUp from './view/signup.js'
const RootStack = createStackNavigator(
{
Home: {
screen: Login
},
Signup: {
screen: SignUp
}
},
{
initialRouteName: 'Home'
}
);
export default class App extends React.Component {
render() {
return <RootStack />;
}
}
原文由 Glenn Parale 发布,翻译遵循 CC BY-SA 4.0 许可协议
React Navigation 3.0 有许多 重大更改,包括根导航器所需的显式应用程序容器。
另请注意,如果您现在使用的是 v4,则导航器已移至单独的存储库。您现在需要从
'react-navigation-stack'
安装和导入。例如import { createStackNavigator } from 'react-navigation-stack'
以下解决方案适用于 v3。更全面的代码示例: