我正在构建一个本机反应元素。元素将具有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检查逻辑放在其他生命周期方法中吗?如果是这样,哪个?