React Native:登录后如何根据用户帐户类型重定向到不同页面?
React Native: How can I redirect after login to different pages depending on the type of account of a user?
我正在使用 expo 构建一个 React Native 应用程序,我想知道如何在登录时向主页发送 "UserTypeA" 并向个人资料发送 "UserTypeB"。
我有一个 UserTypeA 选项卡导航器和一个 UserTypeB 选项卡导航器,两个帐户都可以看到两个页面。
我将我的 UserTypeA 数据和 UserTypeB 数据放在不同的表中,这样我就可以确定哪个用户具有哪种类型。
抱歉,如果不清楚,这是我的第一个问题。
感谢您的帮助!
在您的应用程序主渲染方法中,您可以执行类似的操作。
基本上,您将监听您的 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);
我正在使用 expo 构建一个 React Native 应用程序,我想知道如何在登录时向主页发送 "UserTypeA" 并向个人资料发送 "UserTypeB"。
我有一个 UserTypeA 选项卡导航器和一个 UserTypeB 选项卡导航器,两个帐户都可以看到两个页面。
我将我的 UserTypeA 数据和 UserTypeB 数据放在不同的表中,这样我就可以确定哪个用户具有哪种类型。
抱歉,如果不清楚,这是我的第一个问题。
感谢您的帮助!
在您的应用程序主渲染方法中,您可以执行类似的操作。 基本上,您将监听您的 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);