Nuxt Device Detection with Generate

I installed nuxtjs/device and in localhost it works well and I get what I wanted with ctx.isMobile. But I use nuxt generate and when I deploy my app. it doesnt work. So for this module to work must there be a server? or is there a way to detect device in static generate mode?.

I added this on my modules like this

modules: [
   '@nuxtjs/device',
 ]

and I use it in my components like this

this.$device.isMobile

and like this

ctx.isMobile

Upvotes: 2

Views: 3963

Answers (1)

Pratik149
Pratik149

Reputation: 1108

Look at this part of @nuxtjs/device's documentation

https://github.com/nuxt-community/device-module#options

defaultUserAgent option can be used for npm run generate.

{
  modules: [
    [
      '@nuxtjs/device',
      {defaultUserAgent: 'Mozilla/5.0 (Linux; Android 5.1.1; Nexus 6 Build/LYZ28E) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.39 Mobile Safari/537.36'}
    ]
  ]
}

It says to use defaultUserAgent option to make it work with nuxt generate mode.

Upvotes: 4

Related Questions