23 lines
675 B
TypeScript
23 lines
675 B
TypeScript
// 区分是手机端还是移动端
|
|
|
|
export default defineNuxtRouteMiddleware((to, from) => {
|
|
if (import.meta.client) {
|
|
// 在客户端处理路由
|
|
// 是否是移动端设备
|
|
const isMobile = /(Android|webOS|iPhone|iPod|tablet|BlackBerry|Mobile)/i.test(navigator.userAgent)
|
|
// 是否是手机端路由开头
|
|
const isRouterMobile = to.path.startsWith('/mobile')
|
|
|
|
console.log(isMobile, isRouterMobile);
|
|
|
|
// 移动端并且 不是/m开头路由
|
|
if (isMobile && !isRouterMobile) {
|
|
return navigateTo(`/m`)
|
|
}
|
|
// 不是移动端 是/m开头路由
|
|
if (!isMobile && isRouterMobile) {
|
|
return navigateTo(`/`)
|
|
}
|
|
}
|
|
})
|