React Navigation V5:如何导航到BottomTabNavigator的特定选项卡(反应导航版本5)

时间:2020-03-06 09:23:50

标签: reactjs react-native react-navigation

我有类似这样的代码:

 <Stack.Navigator headerMode='none'>
        <Stack.Screen name="WelcomeScreen" component={WelcomeScreen} />
        <Stack.Screen name="Login" component={Login} />
        <Stack.Screen name="Signup" component={Signup} />
        <Stack.Screen name="OnboardingSummary" component={OnboardingSummary} />  
        <Stack.Screen name="BottomTabs" component={BottomTabs} />
        <Stack.Screen name="Player" component={Player} />
    </Stack.Navigator>

这里的BottomTab是BottomTab BottomTabNavigator

const Tab = createBottomTabNavigator();
    <Tab.Navigator
        tabBar={props => <VialmaTabs {...props} />}
    >
        <Tab.Screen name="Profile" component={profileStack} />
        <Tab.Screen name="Home" component={HomeStack} />
    </Tab.Navigator>

主页堆栈有2个屏幕 UserList,UserDetails

function HomeStack() {
return (
    <RadioStack.Navigator headerMode='none'>
        <RadioStack.Screen name="UserList" component={UserList} />
        <RadioStack.Screen name="UserDetails" component={UserDetails} />
    </RadioStack.Navigator>
);

}

此刻我在播放器屏幕上,我想重定向UserDetails屏幕(它将跳过底部的选项卡和UseList。

我该如何实现?

1 个答案:

答案 0 :(得分:1)

我已找到上述问题的解决方案,我也想与您分享。

import { StackActions, CommonActions } from '@react-navigation/native';

this.props.navigation.dispatch(StackActions.replace('BottomTabs', {
            screen: 'Home', 
                params: {
                         screen: 'UserDetails',
                         params: {
                           [....PARAMS],
                         }
                }
        }));

希望它会对您有所帮助!