feat(pc): 详情页增加吸顶返回列表按钮,首页按筛选签名恢复滚动位置

This commit is contained in:
yml2213
2026-08-15 10:42:09 +08:00
parent a25486201c
commit fbd59ed19f
4 changed files with 176 additions and 2 deletions
+16
View File
@@ -0,0 +1,16 @@
import type { Router } from 'vue-router'
/**
* 返回上一个站内页面(保留其 URL query,即筛选条件),
* 若没有站内历史(例如直接粘贴链接打开详情页),则回首页。
* vue-router 在 push 时会往 history.state 写入 back 字段记录来源页,
* 且该字段始终是站内路径(外部来源时首次进入为 null),可安全判断。
*/
export function goBackOrHome(router: Router) {
const state = window.history.state as { back?: string | null } | null
if (state?.back) {
router.back()
return
}
void router.push('/')
}