mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 10:04:05 +00:00
17 lines
634 B
JavaScript
17 lines
634 B
JavaScript
export default function ({ isHMR, app, store, route, params, error, redirect }) {
|
|
// If middleware is called from hot module replacement, ignore it
|
|
if (isHMR) return
|
|
// Get locale from params
|
|
const locale = params.lang || 'en'
|
|
if (store.state.locales.indexOf(locale) === -1) {
|
|
return error({ message: 'This page could not be found.', statusCode: 404 })
|
|
}
|
|
// Set locale
|
|
store.commit('SET_LANG', locale)
|
|
app.i18n.locale = store.state.locale
|
|
// If route is /en/... -> redirect to /...
|
|
if (locale === 'en' && route.fullPath.indexOf('/en') === 0) {
|
|
return redirect(route.fullPath.replace(/^\/en/, '/'))
|
|
}
|
|
}
|