AI-News/frontend/app/plugins/article-last-list.client.ts
2025-12-04 10:04:21 +08:00

24 lines
758 B
TypeScript

// 记录进入文章详情时的来源列表路径,供抽屉关闭时返回使用
import { useRouter } from 'vue-router'
const LIST_PREFIXES = ['/', '/market', '/community', '/docs']
const KEY = 'article:lastList'
export default defineNuxtPlugin(() => {
if (process.server) return
const router = useRouter()
router.beforeEach((to, from, next) => {
const isArticle = String(to?.path || '').startsWith('/articles/')
const fromPath = String(from?.fullPath || '')
if (isArticle && LIST_PREFIXES.some((p) => fromPath === p || fromPath.startsWith(`${p}/`))) {
try {
window.sessionStorage.setItem(KEY, fromPath)
} catch (err) {
console.warn('[article:lastList] save failed', err)
}
}
next()
})
})