【问题标题】:TypeError: undefined is not a function (near '...(0,_reactNavigationStack.createDrawerNavigator)TypeError: undefined is not a function (near '...(0,_reactNavigationStack.createDrawerNavigator)
【发布时间】:2020-05-12 18:19:58
【问题描述】:

我最近更新了我的 react-native 应用程序,我遇到了这个错误。我不明白代码有什么问题。

import { createAppContainer } from 'react-navigation';
import {
  createDrawerNavigator,
  createStackNavigator,
  createSwitchNavigator,
} from 'react-navigation-stack';

// app stack
const appNavigator = createSwitchNavigator(
  {
    splashScreen: {
      screen: SplashScreen,
    },
    public: {
      screen: publicRoutes,
    },
    private: {
      screen: createDrawerNavigator(
        {
          home: privateRoutes,
        },
        {
          contentComponent: DrawerMenu,
          overlayColor: colors.overlayColor,
        },
      ),
    },
    tnc: {
      screen: TermsAndConditions,
    },
  },
  {
    headerMode: 'none',
    navigationOptions: {
      gesturesEnabled: false,
    },
  },
);

我在这里做错了什么?提前感谢您的帮助。

【问题讨论】:

    标签: react-native


    【解决方案1】:

    您正在尝试从“react-navigation-stack”导入 createDrawerNavigator。 你应该这样做:

    import { createDrawerNavigator } from '@react-navigation/drawer';
    

    在此处阅读有关抽屉导航器的更多信息:https://reactnavigation.org/docs/drawer-navigator/

    【讨论】:

    • 谢谢。有效。我现在对“createSwitchNavigator”也遇到了同样的错误。我要为它安装@react-navigation/switch 吗?
    • 其实你已经不需要 SwitchNavigator 了,因为现在导航支持航班上的航线变更,所以你可以直接使用 if 代替:reactnavigation.org/docs/auth-flow
    猜你喜欢
    • 2023-03-29
    • 2020-02-15
    • 2019-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-26
    • 2015-06-24
    相关资源
    最近更新 更多