简体   繁体   English

react-navigation v5:抛出异常:createStackNavigator 不是函数

[英]react-navigation v5: Exception thrown: createStackNavigator is not a function

I am very new to React, if you need any more information let me know and I can provide.我对 React 很陌生,如果您需要更多信息,请告诉我,我可以提供。 I am trying to add bottom tabs.我正在尝试添加底部标签。 I have followed the react-navigation documentation to the best of my ability.我已尽我所能遵循 react-navigation 文档。 I have also scoured the forms and found a few similar questions, but still could not work it out.我也搜索了表格并发现了一些类似的问题,但仍然无法解决。 Thank you for the help.感谢您的帮助。

    import React from 'react';
    import { createStackNavigator } from "@react-navigation/stack";
    import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
    import Icon from 'react-native-ionicons';
    import Ionicons from 'react-native-vector-icons/Ionicons'
    import GreenScreen from "./GreenScreen";
    import RedScreen from "./RedScreen";

const GreenStack = createStackNavigator ();

function GreenStackScreen() {
    return (
        <GreenStack.Navigator>
            <GreenStack.Screen name="Green" component={GreenScreen}/>
            <GreenStack.Screen name="Red" component={RedScreen}/>
        </GreenStack.Navigator>
    );
}

const RedStack = createStackNavigator ();

function RedStackScreen() {

    return (
        <RedStack.Navigator>
            <RedStack.Screen name="Green" component={GreenScreen}/>
            <RedStack.Screen name="Red" component={RedScreen}/>
        </RedStack.Navigator>
    );
}


const Tab = createBottomTabNavigator();

export default function BottomTabs() {
    return (
            <Tab.Navigator
                screenOptions={({route}) => ({
                    tabBarIcon: ({color, size}) => {
                        let iconName;

                        if (route.name ==='Green') {
                            iconName='home'

                        }else if(route.name ==='Red'){
                            iconName='grid'
                        }
                        return <Ionicons name={iconName} size={20} />
                    }
                })} >
                <Tab.Screen name="Green" component={GreenStackScreen}/>
                <Tab.Screen name="Red" component={RedStackScreen} />
            </Tab.Navigator>
    )
}

Your imports are wrong You should import like below你的进口是错误的你应该像下面这样进口

import { createStackNavigator } from '@react-navigation/stack';

And the bottom navigator should be imported like below底部导航器应该像下面一样导入

import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React-Navigation 3:使用 createBottomTabNavigator 和 createStackNavigator 打开模态 - React-Navigation 3: Open modal with createBottomTabNavigator and createStackNavigator @react-navigation/native 升级到 V5 SyntaxError - @react-navigation/native upgrade to V5 SyntaxError 在 BottomTabNavigator react-navigation v5 内嵌套 StackNavigator - Nesting StackNavigator inside BottomTabNavigator react-navigation v5 使用 @react-navigation/stack 中的 createStackNavigator,无法渲染堆栈屏幕 - Using createStackNavigator from @react-navigation/stack, unable to render a stackscreen 如何使用 react-navigation v5 设置初始状态以将屏幕包含为历史记录? - How can I set the initial state using react-navigation v5 to include screens as history? React Navigation - createStackNavigator错误 - “未定义不是函数” - React Navigation - createStackNavigator Error - “Undefined is not a function” 带有 React Navigation v5 的 createSwitchNavigator? - createSwitchNavigator with React Navigation v5? 无法从“node_modules\react-navigation-stack\lib\module\navigators\createStackNavigator.js”解析“react-navigation” - Unable to resolve “react-navigation” from “node_modules\react-navigation-stack\lib\module\navigators\createStackNavigator.js” 在尝试实现React Native Navigation时获取错误“createStackNavigator不是函数” - Getting error “createStackNavigator is not a function” when trying to implement React Native Navigation React Navigation V5 隐藏底部选项卡 - React Navigation V5 Hide Bottom Tabs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM