Reactjs 与Axios完全相同的url不会触发
我在Axios上使用React和Redux。在我的应用程序中,从两个不同的地方调用了具有完全相同变量的完全相同的组件。一个像预期的那样激发到我的API,但另一个从未到达后端。我不知道这怎么可能。它们都使用完全相同的URL到达我的Redux操作,那么这怎么可能呢 组件内部的按钮:Reactjs 与Axios完全相同的url不会触发,reactjs,redux,axios,Reactjs,Redux,Axios,我在Axios上使用React和Redux。在我的应用程序中,从两个不同的地方调用了具有完全相同变量的完全相同的组件。一个像预期的那样激发到我的API,但另一个从未到达后端。我不知道这怎么可能。它们都使用完全相同的URL到达我的Redux操作,那么这怎么可能呢 组件内部的按钮: <button onClick={e => { // Same button used for both e.stopPropagation(); deletePost({ _id
<button
onClick={e => {
// Same button used for both
e.stopPropagation();
deletePost({ _id, postType, isMainPost });
}}>
Delete
</button>
后端api:
router.delete('/:postType/:_id', auth, async (req, res) => {
try {
// Only one reaches here...
const { _id, postType } = req.params;
console.log('OUTPUT: _id', _id);
console.log('OUTPUT: postType', postType);
} catch (error) {
console.error(error);
}
});
是此日志的输出
console.log('output:url',url)代码>两个操作都相同?您是否尝试在后端和前端之间隔离问题?您可以使用test-get请求来测试:示例:https://httpbin.org/get
是此日志的输出console.log('output:url',url)代码>两个操作都相同?您是否尝试在后端和前端之间隔离问题?您可以使用test-get请求来测试:示例:https://httpbin.org/get
router.delete('/:postType/:_id', auth, async (req, res) => {
try {
// Only one reaches here...
const { _id, postType } = req.params;
console.log('OUTPUT: _id', _id);
console.log('OUTPUT: postType', postType);
} catch (error) {
console.error(error);
}
});