我有一个带有redux存储和axios中间件的简单react-native应用程序。我的应用程序中的底部导航包含4个标签。打开“配置文件”选项卡之前,我需要检查是否经过授权的用户。如果是,请转到配置文件,如果不是,请转到验证。我该怎么办?
我当前的越野车导航示例(在导航器内部的服务器上进行身份验证检查请求):
const tabNavigator = createBottomTabNavigator(
{
Home: { screen: HomeScreen },
Cart: { screen: CartStack },
Delivery: { screen: DeliveryScreen },
Profile: { screen: ProfileStack },
// Item: { screen: ItemScreen }
},
{
defaultNavigationOptions: ({ navigation }) => {
const { routeName } = navigation.state;
return {
tabBarIcon: tabBarIcon(routeName),
tabBarLabel: titleMapping[routeName],
tabBarOnPress: ({ navigation, defaultHandler }) => {
if (navigation.state.routeName == 'Profile') {
client.get('/me').then(function(response) {
console.log(response)
if (response.data == null) {
navigation.navigate("Auth")
} else {
defaultHandler();
}
});
} else {
defaultHandler();
}
},
};
},
tabBarOptions: {
activeTintColor: Colors.buttonMain,
style: {
backgroundColor: Colors.background,
paddingBottom: 5,
},
},
},
);