如何在React Native中从自定义导航器导航到createBottomTabNavigator?

问题描述 投票:2回答:1

我有一个自定义导航器,因为我想使用后滑动手势返回上一个屏幕。下面是调用导航器的主文件的代码。

const MainSwipeStack = () => {
    return(
        <Navigator>
            <Route name="LoggedOutHome" component={LoggedOutHome} />
            <Route name="SignUp" component={SignUp} />
            <Route name="SignupUsername" component={SignupUsername} />
            <Route name="Login" component={Login} /> 
        </Navigator> 
    );
}

export default createSwitchNavigator({
    SwipeStack: {screen: MainSwipeStack},
    TabHolder: {screen: TabHolder}
}, {
    initialRouteName: 'SwipeStack',
    headerMode: 'none',
});

以下是Navigator.js代码的链接。 (我没有在这里添加代码,因为它是一个很长的代码。)

https://gist.github.com/shubham6996/a4197d2d0b664d4aabe01091cac6c91e

TabHolder带我到有createBottomTabNavigator的屏幕。

所以,现在我无法从Login屏幕导航到TabHolder堆栈。

如何从自定义导航器中的Login导航到TabHolder堆栈?

react-native react-native-android react-navigation
1个回答
1
投票

好像导航道具不存在,

试试这个

export default withNavigation(Login);

在登录和是也导入

import {withNavigation} from 'react-navigation'

未直接在导航器中使用的组件默认情况下没有导航道具。

所以你需要将它作为普通的道具传递给你,

<Login navigation={this.props.navigation} 

但是在堆栈中我们没有导航道具所以我们不能这样通过(或者如果我们有道具那就是idk ......)

所以替代选项是withNavigationwithNaviagtionFocus,如上所示

查找有关withNavigation的详细信息

© www.soinside.com 2019 - 2024. All rights reserved.