使用bottomtabnavigator时,无法从stacknavigator进行屏幕导航

时间:2020-02-25 07:22:47

标签: react-native react-navigation stack-navigator

我是新来的本地人,我在一个屏幕到另一个屏幕之间导航时遇到问题。 我正在像这样使用stacknavigator:

const RootStack = createStackNavigator(
    {
        Splash: { screen: SplashScreen},
        Mobile:{screen:MobileAuthentication} ,
        Code:{screen:CodeAuthentication} ,
        Home: { screen: HomeScreen },
        ProfileScreen: { screen: ProfileScreen },
        ProfileDetails: { screen: ProfileDetails },
    },
    { initialRouteName: 'Splash'}
);
const AppContainer = createAppContainer(RootStack);

在主屏幕中,我正在使用buttomtabnavigator

const bottomTabNavigator = createBottomTabNavigator(
  {
    A: {
      screen: ProfileScreen,
      navigationOptions: {
...
      }
    },
    B: {
      screen: FilterScreen,
      navigationOptions: {
...
      }
    },
  },
  {
    initialRouteName: 'FilterScreen',
    tabBarOptions: {
      activeTintColor: '#3F51B5'
    }
  }
);
const AppContainer = createAppContainer(bottomTabNavigator);

问题是,当我想通过ProfileScreenProfileDetails导航到onpress时,它不起作用

       <ProfileBtn
          onPress={() => {
            console.log('item Clicked'),
            this.props.navigation.navigate('ProfileDetails')
          } }
         />

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

也许您应该尝试使用“ smthg”这样的选项(对于您的每个堆栈屏幕或至少要在其中使用的屏幕)将“导航”传递到stackNavigator创建中:

options={({route, navigation}) => (
                {headerTitle: 'Splash',
                route: {route}, 
                navigation: {navigation}}
            )}

如果这不是答案,请向我们提供您在控制台中看到的错误。