HTTP请求按预期工作,但我看到对/%3Canonymous%3E
的附加请求返回了404。这导致Redux中出现以下错误:
未处理的拒绝(TypeError):无法读取的属性“数据” 未定义
我在其他组件(例如,来自用户组件的/ api / users)对其他路由的请求中看不到404。我已经更改了获取请求和路由以匹配用户的获取请求和路由,但是问题仍然存在。我已经在邮递员中尝试过该请求,并且它以预期的结果响应。 /%3Canonymous%3E的附加请求仅在通过浏览器(从应用程序)向订单资源发出获取请求时发生。
获取请求:
export const getOrders = () => dispatch => {
axios
.get("api/orders/")
.then(res =>
dispatch({
type: GET_ORDERS,
payload: res.data
})
)
.catch(err =>
dispatch({
type: GET_ERRORS,
payload: err.response.data
})
);
};
订购路线:
router.get(
"/",
(req, res) => {
Order.find()
.then(orders => res.json(orders))
.catch(err => {
res.json(err);
});
}
);
getOrder Reducer:
case GET_ORDERS:
return {
...state,
allOrders:
action.payload
};
整个订单减少器:
import {
GET_ORDERS,
ADD_ORDER,
EDIT_ORDER,
SET_EDITING_ORDER
} from "../actions/types";
const initialState = {
editingOrder: {},
allOrders: [],
editedOrder: {}
};
export default function(state = initialState, action) {
switch (action.type) {
case SET_EDITING_ORDER:
return {
...state,
editingOrder: action.payload
};
case EDIT_ORDER:
return {
...state,
editedOrder: action.payload
};
case GET_ORDERS:
return {
...state,
allOrders: action.payload
};
case ADD_ORDER:
// state.allOrders.push(action.payload);
return {
...state,
allOrders: [...state.allOrders, action.payload]
// newOrder: action.payload [don't need this
};
default:
return state;
}
}
以redux状态返回并填充数据,但是该额外的随机请求导致了问题。提前谢谢。