簡體   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