Nuxt/examples/i18n/middleware/i18n.js

9 lines
307 B
JavaScript
Raw Normal View History

2017-02-08 17:49:16 +00:00
export default async function ({ store, params, error }) {
const lang = params.lang || 'en'
if (!store.state.lang.locales.includes(lang)) {
2017-02-10 11:55:51 +00:00
await store.dispatch('lang/setLang', 'en')
2017-02-08 17:49:16 +00:00
return error({ message: 'Page not found', statusCode: 404 })
}
2017-02-10 11:55:51 +00:00
await store.dispatch('lang/setLang', lang)
2017-02-08 17:49:16 +00:00
}