Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 服务器的响应状态为404(未找到)问题_Reactjs_Api_Http Status Code 404_Mern - Fatal编程技术网

Reactjs 服务器的响应状态为404(未找到)问题

Reactjs 服务器的响应状态为404(未找到)问题,reactjs,api,http-status-code-404,mern,Reactjs,Api,Http Status Code 404,Mern,我在我的项目中面临一个404问题 Failed to load resource: the server responded with a status of 404 (Not Found) 我不知道问题出在哪里。我是梅恩·斯塔克的新手。我如何解决这个问题 这是我的PostAPI router.post("/", async (req, res) => { try { const _id = await getNextSequence("cour

我在我的项目中面临一个404问题

Failed to load resource: the server responded with a status of 404 (Not Found)
我不知道问题出在哪里。我是梅恩·斯塔克的新手。我如何解决这个问题

这是我的PostAPI

router.post("/", async (req, res) => {
  try {
    const _id = await getNextSequence("courier")
    req.body.id = _id    
    
    const courier = new CourierInfo(req.body)
    await courier.save()
    res.sendStatus(200)
  } catch (error) {
    
    res.sendStatus(500)
  }
})
这是前端的创建方法

// create method
  const submit = async (e, { resetForm }) => {       
      try {
        setCallingBackend(true)
        await axios.post('/courier', e)
        resetForm()
        setAlert({
          showAlert: true,
          severity: 'success',
          message: 'Courier information created successfully!',
        })
      } catch (error) {
        if (error.response.status === 422) {
          setAlert({
            showAlert: true,
            severity: 'error',
            message: 'Courier information already exists!',
          })
        } else {
          console.log(error)
          setAlert({
            showAlert: true,
            severity: 'error',
            message: 'Courier information creation failed!',
          })
        }
      } 
  }

  

我认为你们的终点不一样。在前端,您使用的是“/courier”,而在后端,您只有“/”