不变违规:此导航器缺少导航道具。在反应导航3

问题描述 投票:1回答:1

我是新来的本地反应,我正在尝试使用堆栈导航创建一个应用程序。这就是我在App.js上的内容

import React from "react";
import { View, Text } from "react-native";
// Import React Navigation
import { createStackNavigator, createAppContainer } from 'react-navigation'

// Import the screens
import Main from './components/Main';
import Chat from './components/Chat';



// Create the navigator
const navigator = createStackNavigator({
  Main: { screen: Main },
  Chat: { screen: Chat },
});
const App = createAppContainer(navigator)


export default 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

This error is located at:
    in Navigator (at createKeyboardAwareNavigator.js:12)
    in KeyboardAwareNavigator (at registerRootComponent.js:17)
    in RootErrorBoundary (at registerRootComponent.js:16)
    in ExpoRootComponent (at renderApplication.js:34)
    in RCTView (at View.js:44)
    in RCTView (at View.js:44)
    in AppContainer (at renderApplication.js:33)
- node_modules/@react-navigation/core/src/navigators/createNavigator.js:19:8 in getDerivedStateFromProps
- node_modules/react-native/Libraries/Renderer/oss/ReactNativeRenderer-dev.js:7663:46 in applyDerivedStateFromProps
- ... 20 more stack frames from framework internals

我显然做错了,请帮忙

reactjs react-native react-navigation
1个回答
4
投票

official documentationReact Navigation

注意:在v2及更早版本中,React Navigation中的容器由create * Navigator函数自动提供。从v3开始,您需要直接使用容器。在v3中,我们还将createNavigationContainer重命名为createAppContainer。

这意味着,现在您必须明确使用您在代码中完成的Container。

但你仍然使用(出口)navigator而不是App

所以,改变你的最后一行

export default App

© www.soinside.com 2019 - 2024. All rights reserved.