我应该使用哪种React Lifecycle方法来检查React导航TabNavigator中的身份验证状态

时间:2018-09-16 17:53:26

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

我正在构建一个本机反应元素。元素将具有3个react-navigation TabNavigator ,如下所示:

const MainNavigator = createBottomTabNavigator({
      login: { screen: LoginPage },
      signup: { screen: SignupPage },
      main: { screen: HomePage},
    },
    {
      navigationOptions: {
        //tabBarVisible: false, // comment out for testing
      },
      lazyLoad: true
    });

我的主页正在检查componentDidMount

上的身份验证
class HomePage extends Component {
  componentDidMount() {
    const { isAuthenticated, navigation } = this.props;
    console.log("home isAutenticated???>>", isAuthenticated);
    if (!isAuthenticated) {
      navigation.navigate('login');
    }
  }

  .....
}

所有身份验证流程都可以正常工作,直到我使tabBar可见。即使注销后单击主页选项卡,主页仍显示,而没有触发componentDidMount逻辑,这使我想知道是否应将auth检查逻辑放在其他生命周期方法中吗?如果是这样,哪个?

0 个答案:

没有答案