2017-05-02 1 views
1

React 구성 요소를 업데이트하는 데 사용하려는 양식이 있습니다. 제출을 클릭하면 문제가 다시 발생하지 않기 때문에 상태가 변경된 것 같지만 데이터는 유지되지 않습니다. 더 중요한 것은, 내가 변경하려고하는 json 객체를 찾을 수 없다는 404 메시지가 나타납니다.express와 axios로 PUT을 요청하면 계속 404 (React-Redux 양식 사용)

내 동작에 액시 오즈 요청을 사용하는 방법과 관련이 있다고 생각하지만, 오랫동안 이것을 보지 못하면 놀랄 일이 아닙니다. 여기

경로 관련 가벼운 음식이다

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가 완전히 존재하므로 요청이 왜 다르게 생각되는 것 같지 않습니다.

도움을 주시면 감사하겠습니다.

답변

0

알아 냈어. 실제로 내 데이터베이스에 정보를 보내려면 .then을 사용하는 추가 회선이 필요합니다.

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)) 
     } 
    } 
관련 문제