Fix i18n example for alpha3

This commit is contained in:
Sebastien Chopin 2017-05-31 13:21:55 +02:00
parent f089bcfff6
commit 43de27faef
4 changed files with 8 additions and 10 deletions

View File

@ -7,7 +7,7 @@
<nuxt-link class="Header__Link" :to="path('/')" exact>
{{ $t('links.home') }}
</nuxt-link>
<nuxt-link class="Header__Link" :to="path('/about')" active-class="none">
<nuxt-link class="Header__Link" :to="path('/about')" exact>
{{ $t('links.about') }}
</nuxt-link>
<nuxt-link class="Header__Link" v-if="$i18n.locale === 'en'" :to="`/fr` + $route.fullPath" active-class="none" exact>

View File

@ -1,4 +1,7 @@
export default function ({ app, store, route, params, error, redirect }) {
export default function ({ app, store, route, params, error, redirect, hotReload }) {
// Check if middleware called from hot-reloading, ignore
if (hotReload) 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 })
@ -8,6 +11,6 @@ export default function ({ app, store, route, params, error, redirect }) {
app.i18n.locale = store.state.locale
// If route is /en/... -> redirect to /...
if (locale === 'en' && route.fullPath.indexOf('/en') === 0) {
redirect(route.fullPath.replace(/^\/en/, '/'))
return redirect(route.fullPath.replace(/^\/en/, '/'))
}
}

View File

@ -2,7 +2,7 @@
"name": "nuxt-i18n",
"dependencies": {
"nuxt": "latest",
"vue-i18n": "^6.0.0"
"vue-i18n": "^7.0.0"
},
"scripts": {
"dev": "nuxt",

View File

@ -3,12 +3,7 @@ import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
export default ({ isClient, app, store, route, error, redirect }) => {
console.log(route.path)
if (isClient && route.path === '/fr/about') {
return redirect('/about')
}
console.log(error)
export default ({ app, store }) => {
// Set i18n instance on app
// This way we can use it in middleware and pages asyncData/fetch
app.i18n = new VueI18n({