从 api 获取数据后重定向
redirecting after getting data from api
我正在调用 api 并且场景是如果数据来自 api ,那么这意味着服务器是 运行 我必须重定向到下一页,如果没有来自 api 的数据,我应该显示消息服务器不是 运行。无论数据来自什么都无关紧要,数据是否来自我必须重定向,我如何在反应中做到这一点
useEffect(() => {
公理
.get("我的 api")
.then((res) => {
console.log(资源);
场景(res.data);
})
.catch((错误) => {
console.log(错误);
});
}, []);
这是我必须进行的更新,if(res.status===200)
这意味着我们正在从 api.
获取数据
useEffect(()=>{
axios.get('your api')
.then((res)=>{
if (res.status === 200) {
history.push('/Scenes')
}else{
alert("check the server connection")
}
setsts(res.data)
})
.catch((err) => {
console.log(err);
});
}, []);
我正在调用 api 并且场景是如果数据来自 api ,那么这意味着服务器是 运行 我必须重定向到下一页,如果没有来自 api 的数据,我应该显示消息服务器不是 运行。无论数据来自什么都无关紧要,数据是否来自我必须重定向,我如何在反应中做到这一点
useEffect(() => {
公理
.get("我的 api")
.then((res) => {
console.log(资源);
场景(res.data);
})
.catch((错误) => {
console.log(错误);
});
}, []);
这是我必须进行的更新,if(res.status===200) 这意味着我们正在从 api.
获取数据useEffect(()=>{
axios.get('your api')
.then((res)=>{
if (res.status === 200) {
history.push('/Scenes')
}else{
alert("check the server connection")
}
setsts(res.data)
})
.catch((err) => {
console.log(err);
});
}, []);