mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-30 15:22:39 +00:00
Fix i18n example for alpha3
This commit is contained in:
parent
f089bcfff6
commit
43de27faef
@ -7,7 +7,7 @@
|
|||||||
<nuxt-link class="Header__Link" :to="path('/')" exact>
|
<nuxt-link class="Header__Link" :to="path('/')" exact>
|
||||||
{{ $t('links.home') }}
|
{{ $t('links.home') }}
|
||||||
</nuxt-link>
|
</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') }}
|
{{ $t('links.about') }}
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
<nuxt-link class="Header__Link" v-if="$i18n.locale === 'en'" :to="`/fr` + $route.fullPath" active-class="none" exact>
|
<nuxt-link class="Header__Link" v-if="$i18n.locale === 'en'" :to="`/fr` + $route.fullPath" active-class="none" exact>
|
||||||
|
@ -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'
|
const locale = params.lang || 'en'
|
||||||
if (store.state.locales.indexOf(locale) === -1) {
|
if (store.state.locales.indexOf(locale) === -1) {
|
||||||
return error({ message: 'This page could not be found.', statusCode: 404 })
|
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
|
app.i18n.locale = store.state.locale
|
||||||
// If route is /en/... -> redirect to /...
|
// If route is /en/... -> redirect to /...
|
||||||
if (locale === 'en' && route.fullPath.indexOf('/en') === 0) {
|
if (locale === 'en' && route.fullPath.indexOf('/en') === 0) {
|
||||||
redirect(route.fullPath.replace(/^\/en/, '/'))
|
return redirect(route.fullPath.replace(/^\/en/, '/'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"name": "nuxt-i18n",
|
"name": "nuxt-i18n",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nuxt": "latest",
|
"nuxt": "latest",
|
||||||
"vue-i18n": "^6.0.0"
|
"vue-i18n": "^7.0.0"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "nuxt",
|
"dev": "nuxt",
|
||||||
|
@ -3,12 +3,7 @@ import VueI18n from 'vue-i18n'
|
|||||||
|
|
||||||
Vue.use(VueI18n)
|
Vue.use(VueI18n)
|
||||||
|
|
||||||
export default ({ isClient, app, store, route, error, redirect }) => {
|
export default ({ app, store }) => {
|
||||||
console.log(route.path)
|
|
||||||
if (isClient && route.path === '/fr/about') {
|
|
||||||
return redirect('/about')
|
|
||||||
}
|
|
||||||
console.log(error)
|
|
||||||
// Set i18n instance on app
|
// Set i18n instance on app
|
||||||
// This way we can use it in middleware and pages asyncData/fetch
|
// This way we can use it in middleware and pages asyncData/fetch
|
||||||
app.i18n = new VueI18n({
|
app.i18n = new VueI18n({
|
||||||
|
Loading…
Reference in New Issue
Block a user