【发布时间】:2022-07-26 00:32:59
【问题描述】:
我有一个页面 /studentprofile ,用户可以在其中查看他们的个人资料详细信息,当用户单击“编辑个人资料”按钮时,他们将被带到 /editprofile 并能够使用表单更新他们的个人资料。一旦他们单击“更新”按钮,就会调用 editProfile() 函数,api 会分别更新详细信息,然后将用户导航回 /studentprofile。但是,一旦用户返回 /studentprofile 他们的旧数据只会显示,您必须手动重新加载页面才能看到更新的数据,有没有办法解决这个问题,这样用户就不必自己重新加载页面?
这是按下更新按钮时将触发的功能。我正在使用反应路由器 dom v6.3.0
const navigate = useNavigate();
function editProfile() {
const studentid = localStorage.getItem('studentid')
api.put(`/students/${studentid}`, data)
.then(
navigate('/studentProfile')
)
}
【问题讨论】: