im正在执行从API提取数据的验证表单,所以我做了一个状态为“ isLogged”,它开始为false,然后如果auth工作变为true,所以我试图用if条件渲染if-else语句是“ isLogged” === true,那么我应该将用户导航到仪表板页面,否则当“ isLogged”其为false时,我将呈现整个表单组件,但是我不知道如何在没有屏幕的情况下导航用户onPress或渲染组件,我只想调用一个函数进行导航或其他操作,以寻求帮助!
[CODE:]
class Login extends Component {
constructor(props) {
super(props);
this.state = {
username: null,
password: null,
isLogged: false,
}
}
render() {
if (this.state.isLogged) {
# the command which navigate the user to Dashboard page
} else {
return (
# The whole component code>
);
}
}
}
您可以使用从react-router-dom重定向组件;
render() {
if (this.state.isLogged) {
return <Redirect to={DashboardPage} />
} else {
return (
# The whole component code>
);
}
}