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
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c446">#c446</a>)</em></sub></div>