我有一个自定义导航器,因为我想使用后滑动手势返回上一个屏幕。下面是调用导航器的主文件的代码。
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
堆栈?
好像导航道具不存在,
试试这个
export default withNavigation(Login);
在登录和是也导入
import {withNavigation} from 'react-navigation'
未直接在导航器中使用的组件默认情况下没有导航道具。
所以你需要将它作为普通的道具传递给你,
<Login navigation={this.props.navigation}
但是在堆栈中我们没有导航道具所以我们不能这样通过(或者如果我们有道具那就是idk ......)
所以替代选项是withNavigation
和withNaviagtionFocus
,如上所示
查找有关withNavigation的详细信息