search

Home  >  Q&A  >  body text

html5 - How to adapt Vuejs server-side rendering and routing to mobile and PC

My current approach is, but if I do this, the front-end js will directly report an error:

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
  }
  
  

I would like to know what the industry’s common practice will be like? For example, I have written two pages a.vue and a-mobile.vue. How can I control the same route http://a.com to point to different page files

大家讲道理大家讲道理2731 days ago1087

reply all(1)I'll reply

  • typecho

    typecho2017-07-06 10:36:58

    Use iview or v-strap

    reply
    0
  • Cancelreply