我正在使用Postgresql数据库在React on Express上开发一个Web应用程序,并且正在努力允许用户删除/更新其配置文件。 我已经为这些更改更新了控制器、模型和路由,但是我在确定从 React 组件将获取请求发送到何处时遇到了问题。 每当我尝试运行删除或更新时,我的终端都会收到以下内容:
PUT /api/auth/1 400 3.468 ms - 24
--- undefined /robots.txt
我在这里检查了其他线程,但无法找到如何确定我应该为这些功能指向哪个 URL。 我想一旦我明白它应该按预期工作。 以下是我的身份验证路由和我设置的功能,如果有人可以建议我如何确定将其指向哪个 URL,我将不胜感激。
// handle profile update/delete
authRouter.route('/dashboard')
.get(usersController.show)
.put(usersController.update)
.delete(usersController.delete)
用户更新/删除功能:
handleUpdateSubmit(e, data, id) {
e.preventDefault()
console.log('clicked')
fetch(`/api/auth/${id}`, {
method: 'PUT',
credentials: 'include',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
}).then(res => res.json())
.then(res => {
this.setState({
fireRedirect: true,
redirectPath: '/dashboard'
})
}).catch(err => console.log(err))
}
userDelete(id) {
fetch(`/api/auth/${id}`, {
method: 'DELETE',
}).then(res => res.json())
.then(res => {
this.setState({
fireRedirect: true,
redirectPath: '/'
})
}).catch(err => console.log(err))
}
如果有任何信息有助于解决这个问题,请告诉我,我会立即提供,谢谢!
忘了跟进这个,问题在于我的函数是如何排序的。 我移动了我的身份验证。登录/注销/注册功能下的路由代码,它按预期工作。