使用express提交请求,axios不断给我404(使用React Redux表单)

使用express提交请求,axios不断给我404(使用React Redux表单),express,http-status-code-404,react-redux,put,axios,Express,Http Status Code 404,React Redux,Put,Axios,我有一个表单,我正试图使用它来更新React组件。状态似乎被改变了,因为当我点击submit时,它不会重新呈现任何问题,但数据不会持久。更重要的是,我得到一个404消息,说我试图更改的json对象找不到 我认为这与我如何尝试在我的操作中使用axios请求有关,但如果我看这个太久了,我不会感到惊讶 以下是相关的花絮 路线 const User = db.model('user') const router = require('express').Router(); router.put('/:

我有一个表单,我正试图使用它来更新React组件。状态似乎被改变了,因为当我点击submit时,它不会重新呈现任何问题,但数据不会持久。更重要的是,我得到一个404消息,说我试图更改的json对象找不到

我认为这与我如何尝试在我的操作中使用axios请求有关,但如果我看这个太久了,我不会感到惊讶

以下是相关的花絮

路线

const User = db.model('user')
const router = require('express').Router();

router.put('/:id', (req, res, next) => {
  User.findById(req.params.id)
  .then(user => user.update(req.body))
  .then(updated => res.status(201).json(updated))
  .catch(next)
})
const editUser = (userId, userInfo) => ({
  type: UPDATE_USER,
  userId,
  userInfo
})

export const updateUser = function(id, info) {
  return dispatch => {
    dispatch(editUser(id, info))
    axios.put(`/api/users/${id}`, {info})
      .catch(err => console.error("Wasn't able to update user.", err))
  }
}
行动

const User = db.model('user')
const router = require('express').Router();

router.put('/:id', (req, res, next) => {
  User.findById(req.params.id)
  .then(user => user.update(req.body))
  .then(updated => res.status(201).json(updated))
  .catch(next)
})
const editUser = (userId, userInfo) => ({
  type: UPDATE_USER,
  userId,
  userInfo
})

export const updateUser = function(id, info) {
  return dispatch => {
    dispatch(editUser(id, info))
    axios.put(`/api/users/${id}`, {info})
      .catch(err => console.error("Wasn't able to update user.", err))
  }
}
下面是我得到的错误

POST http://localhost:1337/api/users/1  Wasn't able to update property. 404 (Not Found) 
Error: Request failed with status code 404
        at createError (createError.js:15)
        at settle (settle.js:18)
        at XMLHttpRequest.handleLoad (xhr.js:77)
这个URI是完全存在的,所以我真的不明白为什么这个请求会有不同的想法


感谢您的帮助

找到了答案。需要一个额外的行,使用
。然后
将信息实际发送到my db

export const updateUser = function(id, info) {
      return dispatch => {
        dispatch(editUser(id, info))
        axios.put(`/api/forSale/${id}`, info)
          .then(res => res.data)
          .catch(err => console.error("Wasn't able to update property.", err))
      }
    }

我明白了。需要一个额外的行,使用
。然后
将信息实际发送到my db

export const updateUser = function(id, info) {
      return dispatch => {
        dispatch(editUser(id, info))
        axios.put(`/api/forSale/${id}`, info)
          .then(res => res.data)
          .catch(err => console.error("Wasn't able to update property.", err))
      }
    }