2

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

1 Answers1

4

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.

Pratik149
  • 1,109
  • 1
  • 9
  • 16
  • Thanks for the answer. It might be used to set defaultuseragent, which means whatever device enters the website will be regarded as whatever value is provided in defaultuseragent. which is not really usefull in my opinion. – user10877669498464651468548513 Aug 08 '20 at 21:23
  • for static mode there's not easy way to detect user device before app initialization. – user10877669498464651468548513 Aug 08 '20 at 21:24
  • Did you try doing this before concluding that this won't work for static mode? May be the way nuxt/device module is implemented, it requires us to set defaultUserAgent in order to make it work in static mode. Just check it, and let me know. – Pratik149 Sep 11 '20 at 06:28