nuxt.js middleware 中间件实现判断手机端跳转
作者:互联网
vue里面写法如下:
export default function ({ isServer, req, redirect, route }) { let pcOrigin = 'https://www.xxxxx.com' let mobileOrigin = 'https://m.xxxxx.com' let isMobile = (ua) => { return !!ua.match(/AppleWebKit.*Mobile.*/) } let userAgent = req ? req.headers['user-agent'] : navigator.userAgent || '' if(route.params.novel_id || route.params.comic_id) { return isMobile(userAgent) ? redirect(mobileOrigin + route.fullPath) : '' } else { if(/ipad/i.test(userAgent)){ // 不包含ipad return } else { return isMobile(userAgent) ? redirect(mobileOrigin + '/app') : '' } } // return isMobile(userAgent) ? redirect(mobileOrigin + route.fullPath) : '' // 使用redirect 重定向到外链需要加上前缀:http / https }
标签:redirect,return,middleware,中间件,跳转,mobileOrigin,userAgent,route,isMobile 来源: https://www.cnblogs.com/zhpblog/p/15469159.html