react-native - React Native:注销时重定向到另一个堆栈导航
问题描述
我使用 asyncStorage 在我的应用程序中更改登录/退出状态,当我单击 logOut 时,我将状态更改为 false,然后我必须将用户重定向到另一个堆栈导航(loginStackNavigation)
<TouchableOpacity
style={[styles...]}
onPress={() => onSignOut().then(this.navigateToScreen('LoggingStackNavigation'))}
>
...
</TouchableOpacity>
附言。onSignOut() 函数更改存储在 asyncstorage 中的值
这是 navigateToScreen() 函数:
navigateToScreen = (route) => (
() => {
const navigateAction = NavigationActions.navigate({
routeName: route
});
this.props.navigation.dispatch(navigateAction);
this.props.navigation.closeDrawer();
});
我该怎么做才能将用户重定向到LoggingStackNavigation
解决方案
我认为您应该使用 Switch Navigator 来包装您的 2 个导航器:
import { createSwitchNavigator } from 'react-navigation';
const routesConfig = {
NotAuthenticated :{screen: loggedOutStack},
Authenticated : { screen: loggedInStack}
}
const SwitchNavigatorConfig= {
initialRouteName: "NotAuthenticated"
}
export const createSwitchNavigator(RoutesConfig, SwitchNavigatorConfigs)
然后你可以navigation.navigate("NotAuthenticated")
在需要的时候
推荐阅读
- excel - 将公式应用于 Excel 中的条件格式
- database - 从数据库中获取 Primavera p6 资源分配?
- ios - Swift:是否可以调整音量并保存音量调整后的音频文件
- c# - C# 存储来自 Android 流的 3gpp 文件
- python - 将 .py 文件转换为 .exe 文件后,cv2.imwrite 无法工作。有人可以帮我解决这个问题吗?
- mysql - 在 SQL 查询中的 WHERE 语句中具有条件
- javascript - 如何在 Sequelize 中设置两列相乘的 where 条件?
- vue.js - Vuetify 活动类十六进制文本颜色
- c - Mbedtls_pk_parse_public_key 返回 0xfffffff0 和 secp256k1 公钥
- sql - 为什么不存在的地方返回存在的ID?