feat: 实现自适应路由切换,根据 User-Agent 及屏幕大小自动导航 PC/Mobile 视图

This commit is contained in:
yml
2026-05-25 09:10:08 +08:00
parent 3a6e6e6a33
commit 26ee082b95
2 changed files with 76 additions and 6 deletions
+13 -3
View File
@@ -5,7 +5,7 @@ import { useSessionStore } from '@/stores/session'
import { getAccessToken, getLoginPath } from '@/utils/authStorage'
import { accountRoutes } from './accountRoutes'
import { adminRoutes } from './adminRoutes'
import { isMobileHost, toMobilePath } from './mobileHost'
import { isMobileHost, isMobileDevice, getMobilePath, getPcPath } from './mobileHost'
import { mobileRoutes } from './mobileRoutes'
import { publicRoutes } from './publicRoutes'
import { sellerRoutes } from './sellerRoutes'
@@ -22,8 +22,18 @@ const router = createRouter({
})
router.beforeEach(async (to) => {
if (isMobileHost() && to.path !== toMobilePath(to.path)) {
return { path: toMobilePath(to.path), query: to.query, hash: to.hash }
const isMobile = isMobileHost() || isMobileDevice()
if (isMobile) {
const targetPath = getMobilePath(to.path)
if (to.path !== targetPath) {
return { path: targetPath, query: to.query, hash: to.hash }
}
} else {
const targetPath = getPcPath(to.path)
if (to.path !== targetPath) {
return { path: targetPath, query: to.query, hash: to.hash }
}
}
if (to.meta.requiresAuth) {