Node.js Axios从数据库删除后删除404

Node.js Axios从数据库删除后删除404,node.js,reactjs,mongodb,axios,Node.js,Reactjs,Mongodb,Axios,我正在使用axios从React前端向带有mongo DB的node js express后端发送删除请求。虽然数据确实从我的数据库中删除了,但我仍然得到一个错误404未找到 这是反应代码 axios .delete(`http://localhost:8000/notes/${id}`) .then(res => { console.log("The response is "+res.data) }) .catch(err => {

我正在使用axios从React前端向带有mongo DB的node js express后端发送删除请求。虽然数据确实从我的数据库中删除了,但我仍然得到一个错误404未找到

这是反应代码

axios
    .delete(`http://localhost:8000/notes/${id}`)
    .then(res => {
      console.log("The response is "+res.data)
    })
    .catch(err => {
      console.log("There was an error "+ JSON.stringify(err.response))
    });
下面是node js express代码app.js

app.delete("/notes/:notesId", cors(), function(req, res) {
  const query={_id:req.params.notesId};
  console.log("The notes id is "+ query);  
  Note.findOneAndDelete(query, function(err) {
    if(!err) {
      console.log("The item got successfully deleted");
      res.redirect("/");
    } else {
      console.log(err)
    }
  })
})
请注意,该条目已从我的数据库中删除,但我在浏览器控制台中遇到此错误:

xhr.js:178 DELETE http://localhost:8000/ 404 (Not Found)
App.jsx:26 There was an error {"data":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot DELETE /</pre>\n</body>\n</html>\n","status":404,"statusText":"Not Found","headers":{"content-length":"142","content-type":"text/html; charset=utf-8"},"config":{"url":"http://localhost:8000/notes/5ee130b65dc5f521acf60f38","method":"delete","headers":{"Accept":"application/json, text/plain, */*"},"transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfHeaderName":"X-XSRF-TOKEN","maxContentLength":-1},"request":{}}
xhr.js:178删除http://localhost:8000/ 404(未找到)
App.jsx:26出现错误{“数据”:“\n\n\n\n\n无法删除/\n\n\n”,“状态”:404,“状态文本”:“未找到”,“标题”:{“内容长度”:“142”,“内容类型”:“文本/html;字符集=utf-8”},“配置”:{“url”:”http://localhost:8000/notes/5ee130b65dc5f521acf60f38“,”方法“:”删除“,”标题“:{”接受“:”应用程序/json,文本/plain,*/*”},“transformRequest:[null],“transformResponse:[null],“timeout”:0,“xsrfCookieName:“XSRF-TOKEN”,“xsrfHeaderName:“X-XSRF-TOKEN”,“maxContentLength:-1}”,请求:{}

我试图点击完整的url直到notes id,但它只考虑直到根用户尝试修改res,以便在对象被删除时发送200 OK状态。您也可以发送一条消息,让前端以这种方式显示

不管怎样,一个简单的
res.status(200).end();
也足以满足您的情况

if(!err) {
    res.status(200).json({ message: 'The item got successfully deleted', error: false });
} else {
    res.status(500).json({message : 'Oops and error occurred', error : true});