首页 > 解决方案 > 如何在本机反应中导航到 BottomTabNavigator 内的另一个导航?

问题描述

我想从 BottomTabNavigator 导航到堆栈导航器。但是,当我在 BottomTabNavigator 中分​​配堆栈导航器时,会The component for route 'route_name' must be a React component显示错误。

在此处输入图像描述

这是我的代码:

const BottomTabNavigator = createAppContainer(createBottomTabNavigator(
  {
    Home: {
      screen: HomeScreen,
      navigationOptions:{
        tabBarLabel: 'Home',
        tabBarIcon: ({ tintColor }) => (  
          <View>  
              <Icon style={[{color: tintColor}]} size={25} name={'ios-home'}/>
          </View>)
        }
    },
    Profile: {
      screen: ProfileStackNavigator,
      navigationOptions:({ navigation }) => ({
        tabBarLabel: 'Profile',
        tabBarIcon: ({ tintColor }) => (  
          <View>  
              <Icon style={[{color: tintColor}]} size={25} name={'ios-contact'}/>
          </View>),
        }),
    },
  },
  {
    tabBarOptions: {
      activeTintColor: '#2383F7',
      // inactiveTintColor: 'gray',
    },
  }
));

const ProfileStackNavigator = createAppContainer(createStackNavigator({
  ProfileHome: 
  {
    screen: ProfileScreen,
    // headerMode: 'none',
    navigationOptions:
    {
      header: null,
    }

  },
  ChangePasswordFromProfile: 
  {
    screen: ChangePasswordScreen,
    // navigationOptions:
    // {
    //   header: null,
    // }
  }
}))

这是导航的所有版本:

“反应导航”:“^4.0.10”,“反应导航抽屉”:“^2.3.3”,“反应导航堆栈”:“^1.10.3”,“反应导航标签” : "^2.6.2"

提前致谢

标签: react-nativereact-navigation

解决方案


在您创建 BottomTabNavigator 时,尚未创建 ProfileStackNavigator 变量。所以,把你的const ProfileStackNavigator = ...代码移到上面const BottomTabNavigator = ...


推荐阅读