如何在登录api的Json响应后,在react native中重定向用户



请注意,我正在用react native构建一个应用程序,我用php编写登录api,但我在成功登录到仪表板后重定向用户时遇到了问题,这是我在下面的代码

从"React"导入React,{Component};从"react native"导入{View,Button,Text,StyleSheet,TextInput,Dimensions};从"@expo/vector icons"导入{FontAwesome5};从"@expo/vector icons"导入{Feather};

const{width,height}=Dimensions.get("window"(;导出默认类SignIn扩展组件{

static navigationOptions = ({navigation}) => ({
});
constructor(props) {
super(props);
this.state = {username: "",password: "" };
}
SignUp = () => {
this.props.navigation.navigate('CreateAccount')
};
InsertRecord = () => {
var username = this.state.username;
var password = this.state.password;
if (username=="") {

alert("Username field cannot be empty")
return false;
}
else if(password==""){

alert("Password field cannot be empty")
}
else{
var InsertAPIURL ='https://moneystackng.com/api/login_api.php';
var headers={
'Accept':'application/json',
'Content-Type':'application/json'
};
var Data = {
username:username,
password:password
};
fetch(InsertAPIURL,
{
method:'POST',
headers: headers,
body: JSON.stringify(Data),
})
.then((response)=>response.json())
.then((response)=>{
if(response == true){

this.props.navigation.navigate("Home", {
params: {
screen: 'Dashboard',
}
});
}
else{
alert(response[0].Message);
}
})
.catch((error)=>
{
alert("Error"+error);
});
}
}

我遇到问题的地方是

this.props.navigation.navigate("Home", {
params: {
screen: 'Dashboard',
}
});

有谁能帮忙吗?

此代码为

this.props.navigation.navigate("Home", {
params: {
screen: 'Dashboard',
}
});

正在导航到";主页";带有";params";对象,要导航到你必须:

this.props.navigation.navigate("Dashboard");

如果你想向仪表板发送一些信息,你可以在页面名称后面传递一个对象:

this.props.navigation.navigate("Dashboard", {foo: bar});

相关内容

  • 没有找到相关文章