重新加载本机反应后,条件导航不起作用

时间:2021-07-24 10:58:37

标签: react-native redux react-redux react-navigation

我已经实现了条件导航,这是 react-navigation 5 中切换导航的替代方法。

 <Stack.Navigator
      screenOptions={{
        headerTintColor: '#fff',
        headerTitleStyle: {
          fontFamily: 'SFUIDisplay-Regular.otf',
          fontWeight: 'bold',
        },
        headerStyle: {
          backgroundColor: '#3e94f0',
        },
        headerTitleAlign: 'center',
      }}
      initialRouteName="login">
      {loginState || isTokenExists ? (
        <Stack.Screen
          name="taskmanager"
          component={Main}
          options={{
            title: 'Task Manager',
            cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
          }}
        />
      ) : (
        <>
          <Stack.Screen
            name="login"
            component={Login}
            options={{
              title: 'Sign In',
            }}
          />
          <Stack.Screen
            name="register"
            component={Register}
            options={{
              title: 'Register',
              cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
            }}
          />
          <Stack.Screen
            name="forgetpassword"
            component={ForgetPassword}
            options={{
              title: 'Forgot Password',
              cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
            }}
          />
        </>
      )}
    </Stack.Navigator>

在注销时,loginStatus 设置为 false,并且令牌被清除。我已经把uid作为token了

 //logout handler
  const logoutHandler = () => {
    console.log('AT logoutHandler', status);
    storeData('clearUID');
    dispatch(actions.loginStatus('', false));
    lowerOptionsToggle();
  };

现在的问题是注销功能工作正常,但如果我在用户登录时重新加载应用程序,它没有注销意味着条件导航不起作用。

1 个答案:

答案 0 :(得分:0)

尝试使用 AsyncStorage 存储/删除登录状态和令牌,并相应地应用条件导航。也尝试应用 initialRouteName 的条件。