fix: 手动切换布局失效 — 仅首页自动适配

- 只对根路径 / 做手机→/m 跳转,不再拦截桌面访问 /m
- 支持 ?view=desktop 或 ?view=mobile 强制覆盖自动检测
- 手动输入的具体路径完全不受影响

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-26 15:56:44 +08:00
parent c71a2ac88e
commit b88b29b745
+10 -10
View File
@@ -75,16 +75,16 @@ router.beforeEach((to, _from, next) => {
return return
} }
// Auto-redirect to mobile layout for mobile devices accessing desktop routes // Auto-redirect: mobile devices hitting root → send to mobile home
const onMobile = isMobile() // Allow manual override via ?view=desktop or ?view=mobile
if (onMobile && to.path === '/' && !to.path.startsWith('/m')) { const viewOverride = to.query.view as string
next('/m') if (!viewOverride) {
return const onMobile = isMobile()
} // Only redirect bare root — explicit paths are honored
// Desktop user accidentally on mobile route → redirect to desktop if (onMobile && (to.path === '/' || to.path === '')) {
if (!onMobile && to.path.startsWith('/m')) { next('/m')
next('/') return
return }
} }
next() next()