繁体   English   中英

重定向到其他页面给我 500 内部服务器错误反应

[英]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])

出现 500 状态错误的一种情况是,当请求 object 在 API 内部传递时不正确。 因此,请查看您的请求 object,了解当您将其发送到服务器时的情况。 既然你提到,它在本地运行良好,我希望你的意思是它是 api 也可用的本地环境。 另一种情况可能是 api 可能未在服务器端正确部署。 您可以尝试检查任一选项。

附件当我错过了请求对象中的输入属性时

当输入对象正确时

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM