Home

Issue: 511

Cannot read property 'useragent' of undefined

[issue link]

I wrote an app that uses express-useragent as middleware and stores it by store directory but when I click on the internal links I got Cannot read property 'useragent' of undefined error.
What’s wrong?

middleware/useragent.js:

export default function ({ req, store }) {
  store.commit('update', req.useragent)
}

store/index.js

export const store = {
  state: {
    platform: '',
    browser: '',
    suggestible: false,
    isIOS: false,
    isAndroid: false
  }
}

export const mutations = {
  update(state, useragent) {
    state.platform = useragent.platform
    state.browser = useragent.browser
    state.isIOS = useragent.isiPad || useragent.isiPhone ? true : false
    state.isAndroid = useragent.isAndroid
  }
}

thanks

This question is available on Nuxt.js community (#c446)