fix: 手动切换布局 — 仅首页首次加载自动适配

检测 _from.name 区分「首次加载」和「应用内导航」:
- 首次: 手机→/m, 桌面→/
- 手动点击切换按钮: 完全尊重用户选择, 不拦截

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-26 16:03:54 +08:00
parent b88b29b745
commit e69d962521
+8 -5
View File
@@ -75,16 +75,19 @@ router.beforeEach((to, _from, next) => {
return
}
// Auto-redirect: mobile devices hitting root → send to mobile home
// Allow manual override via ?view=desktop or ?view=mobile
// Auto-redirect on FIRST entry only (no previous route = fresh page load)
// Don't interfere with manual navigation (user clicked switch button)
const viewOverride = to.query.view as string
if (!viewOverride) {
if (!viewOverride && !_from.name) {
const onMobile = isMobile()
// Only redirect bare root — explicit paths are honored
if (onMobile && (to.path === '/' || to.path === '')) {
if (onMobile && to.path === '/') {
next('/m')
return
}
if (!onMobile && to.path.startsWith('/m')) {
next('/')
return
}
}
next()