[英]Redirecting to other page gives me 500 internal server error in react
我正在我的项目中执行搜索任务。 在其中我必须调用 API 以获得结果。 But before that i have to check whether any state is passed into props or not.If props have any state then call api otherwise redirect us to homepage.On local server it's working fine but on server it gives me 500 internal server error when no props state 已通过。
useEffect(() => {
setProcess(false)
setResults([])
console.log(props.location)
if (props.location.state !== undefined) {
ApiService.searchApi(props.location.state.search, filter).then(response => {
setResults(response.data.results)
setProcess(true)
}).catch(error => {
console.log("error", error)
})
} else {
//when props state is undefined redirect to homepage
history.push("./")
}
}, [filter])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.