Javascript 从底部导航反应本机更改屏幕

Javascript 从底部导航反应本机更改屏幕,javascript,android,react-native,react-native-android,react-navigation,Javascript,Android,React Native,React Native Android,React Navigation,我有两个屏幕 登录屏幕 主屏幕上有两个选项卡。(创建底部导航) 我想从主屏幕访问我的第三个屏幕,但我得到一个错误:“undefined不是一个对象…” 以下是我在app.js中的路线: const Routes = createStackNavigator( { Login: { screen: Login, navigationOptions: ({ navigation }) => ({ header: null, }), }, Main: {

我有两个屏幕

  • 登录屏幕
  • 主屏幕上有两个选项卡。(创建底部导航)
  • 我想从主屏幕访问我的第三个屏幕,但我得到一个错误:“undefined不是一个对象…”

    以下是我在app.js中的路线:

    const Routes = createStackNavigator(
    {
      Login: {
       screen: Login,
    
      navigationOptions: ({ navigation }) => ({
          header: null,
        }),
    
    },
      Main: {
       screen: MainScreenRoutes,
       navigationOptions: ({navigation}) => ({
        header: null,
       }),
    },
       MyProfil: {
        screen: MyProfile,
       }
    },
    {
      initialRouteName: 'Login',
      headerMode: 'screen',
      navigationOptions: {
       ...HeaderStyles,
       animationEnabled: true
      }
     }
    );
    
    我无法从我的选项卡所在的“主”屏幕访问MyProfil

    主配置文件路由器:

    let headerDefaultNavigationConfig = {
      header: props => <CustomHeader {...props} />,
      ...HeaderStyles
    };
    
    const Tab1 = createStackNavigator(
      {
        Domov: {
          screen: HomeScreen,
          navigationOptions: {
          },
    
        },
        /*MyProfil: {
          screen: MyProfil,
        }*/
      },
      {
        navigationOptions: {
          ...headerDefaultNavigationConfig
        }
      }
    );
    
    const Tab2 = createStackNavigator(
      {
        Dnevnik: {
          screen: Diary,
          navigationOptions: {
            headerTitle: "Tab2",
            headerLeft: (
              <Text>Ok</Text>
            )
          },
        }
      },
      {
        navigationOptions: {
          ...headerDefaultNavigationConfig
        }
      }
    );
    
    const bottomTabs = createBottomTabNavigator(
    {
      Domov: Tab1,
      Dnevnik: Tab2,
    },
    {
      initialRouteName: "Domov",
      navigationOptions: ({ navigation }) => ({
          tabBarIcon: ({ focused, tintColor }) => {
            const { routeName } = navigation.state;
            let iconName;
            if (routeName === 'Domov') {
              //iconName = `home${focused ? '' : '-outline'}`;
              iconName='home';
            } else if (routeName === 'Dnevnik') {
              //iconName = `ios-calendar${focused ? '' : '-outline'}`;
              iconName='ios-calendar';
            } 
    
            // if focused return view with line
            if(focused) {
              return (
                <View style={styles.item}>
                    <Icon name={iconName} style={{fontSize: 20, color: '#FFF'}} />
                    <View style={styles.line}></View>
                </View>
              );
            } else {
              return(
                <Icon name={iconName} style={{fontSize: 20, color: '#FFF'}} />
              )
            }
    
          },
    
        }),
        tabBarPosition: 'bottom',
        tabBarOptions: {
          activeTintColor: 'white',
          showLabel: false,
          inactiveTintColor: '#4C2601',
          style: {
            backgroundColor: '#033D51',
          },
          labelStyle: {
            fontSize: 12,
            lineHeight: 30,
          },
        },
        swipeEnabled: true,
    
    });
    
    /*const All = createStackNavigator(
    {
      "Home":{
        screen: bottomTabs,
        navigationOptions: {
            header: null,
        },
      },
      "MyProfil":{screen: MyProfil}, 
    },
    {
        initialRouteName: 'Home',
        headerMode: 'screen',
        navigationOptions: {
          ...HeaderStyles,
          animationEnabled: true
        }
    }
    
    
    
    );
    */
    
    
    
    
    export default bottomTabs;
    

    似乎“导航”字段并没有以某种方式传递到道具中。你调查过这件事吗?谢谢:)我会看的这对我没有帮助(
    const { navigate } = this.props.navigation;         
    navigate('MyProfil');