Vue服务端渲染同路由怎么适配移动和PC

我现在的做法是,但这样做前端js会直接报错:

export function createRouter () {

if (global.mobile) {
    return new Router({
      mode: 'history',
      scrollBehavior: () => ({ y: 0 }),
      routes: [
        { path: '/', component: mobileIndex}
      ]
    })  
}else {
    return new Router({
      mode: 'history',
      scrollBehavior: () => ({ y: 0 }),
      routes: [
        { path: '/', component: index }
      ]
    })  
   }
}

 var is_mobile = function (req) {
    var ua = req.get('User-Agent')
    return /Android|webOS|iPhone|iPod|BlackBerry/i.test(ua);
  }

  console.log('dasjka',req)
  if (is_mobile(req) === true) {
    global.mobile = true
  }else {
    global.mobile = false
  }
 }

我想知道一下业界同用的做法会是什么样的?比如我写好两个页面 a.vue和a-mobile.vue,怎么样控制在同一个路由http://a.com下指向不同页面文件

阅读 704
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题