diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 2bdefa6..919b292 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -1,5 +1,6 @@ import { createRouter, createWebHistory } from 'vue-router' import { useAuthStore } from '@/stores/auth' +import { isMobile } from '@/utils' const router = createRouter({ history: createWebHistory(), @@ -73,6 +74,19 @@ router.beforeEach((to, _from, next) => { next('/login') return } + + // Auto-redirect to mobile layout for mobile devices accessing desktop routes + const onMobile = isMobile() + if (onMobile && to.path === '/' && !to.path.startsWith('/m')) { + next('/m') + return + } + // Desktop user accidentally on mobile route → redirect to desktop + if (!onMobile && to.path.startsWith('/m')) { + next('/') + return + } + next() }) diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index 4778a14..291dd87 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -3,3 +3,9 @@ export function todayStr(): string { const d = new Date() return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}` } + +/** Detect if current device is mobile based on user-agent. */ +export function isMobile(): boolean { + const ua = navigator.userAgent || '' + return /Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone/i.test(ua) +}