feat: 实现自适应路由切换,根据 User-Agent 及屏幕大小自动导航 PC/Mobile 视图
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user