头像上传故障总结(页面跳转到 /?t=时间戳,返回 404) [Copy Link]

三级用户组

现象:上传自定义头像并点击“确认上传并设置头像”后,页面跳转到 /?t=时间戳,返回 404。
影响范围:关闭伪静态时使用查询式路由的头像页,例如 /?my-avatar.htm。

主要原因:
头像上传成功后的前端代码为避免缓存,使用了:

window.location.pathname + ‘?t=’ + Date.now()

当前地址是 /?my-avatar.htm 时,window.location.pathname 只返回 /,会丢失 ?my-avatar.htm 这个路由入口。
因此生成了错误地址:/?t=1784992031982,系统将 t 识别为未知路由,最终返回 404。
修复方法:
修改 view/htm/my_avatar_page.htm:
新增 reloadAvatarPage()。
改为跳回上传表单的 form.action,该值由 my_avatar_url() 生成,能同时兼容查询式路由和伪静态路由。
替换上传成功、审核成功及非 JSON 响应回退路径中的三处错误跳转。

function reloadAvatarPage() {
window.location.href = form.action;
}

修复后上传完成会正确跳转回 /?my-avatar.htm,不再生成错误的时间戳路由。

附上文件,自取自用,本人不对生产未知的风险负责。

my_avatar_page.zip 5.5KB
New Post

Please log in to reply Login

uid:4 三级用户组
Follow
Posts 64
Comments 1
Followers 0
Following 0
Publish
Table of Contents
头像上传故障总结(页面跳转到 /?t=时间戳,返回 404)
This Ad Slot Available
This Ad Slot Available
This Ad Slot Available
Ad Available
Ad Available
Ad Available
Ad Available
Ad Available
Ad Available