refactor: 添加移动端适配和路由中间件

This commit is contained in:
wangqiao
2025-09-01 09:57:10 +08:00
parent 80a48e1e71
commit 7a8f096513
8 changed files with 85 additions and 11 deletions

19
middleware/auth.global.ts Normal file
View File

@ -0,0 +1,19 @@
// 区分是手机端还是移动端
export default defineNuxtRouteMiddleware((to, from) => {
if (import.meta.client) {
// 在客户端处理路由
// 是否是移动端设备
const isMobile = /(Android|webOS|iPhone|iPod|tablet|BlackBerry|Mobile)/i.test(navigator.userAgent)
// 是否是手机端路由
const isRouterMobile = /^\/m\//.test(to.fullPath)
// 移动端并且 不是/m开头路由
if (isMobile && !isRouterMobile) {
return navigateTo(`/m`)
}
// 不是移动端 是/m开头路由
if (!isMobile && isRouterMobile) {
return navigateTo(`/`)
}
}
})

View File

@ -1 +0,0 @@
// 从微信登录重定向到项目 需要获取code值