React Native:如何根据用户的账户类型,在登录后重定向到不同的页面?

问题描述 投票:0回答:1

我正在使用expo构建一个react native应用,我想知道如何在登录后发送一个 "UserTypeA "到主页,并发送一个 "UserTypeB "到Profile。

我有一个UserTypeA标签导航器和一个UserTypeB标签导航器,只有2个页面可以被两个账户看到。

我有我的UserTypeA数据和UserTypeB数据在不同的表中,所以我可以识别哪个用户有哪个类型。

对不起,如果它不清楚,这是我的第一个问题。

谢谢你的帮助

react-native authentication user-accounts
1个回答
0
投票

在你的应用程序的主要渲染方法,你可以做这样的事情。基本上,你会监听你的redux状态,并根据用户类型切换主屏幕。

class MyApp extends PureComponent {
  constructor(props) {
    super(props);
  }

  render() {
    const { auth } = this.props;
    if (auth.userObj.type1) {
      return <Type1MainComponent />;
    } 
    if (auth.userObj.type2) { 
      return <Type2MainComponent />;
    }
    return <LoginScreen />;
  }
}

function mapStateToProps(state) {
  const { auth } = state;
  return { auth };
}

export default connect(mapStateToProps)(MyApp);

© www.soinside.com 2019 - 2024. All rights reserved.