mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +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>
|
||||
{{ $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>
|
||||
|
@ -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/, '/'))
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
"name": "nuxt-i18n",
|
||||
"dependencies": {
|
||||
"nuxt": "latest",
|
||||
"vue-i18n": "^6.0.0"
|
||||
"vue-i18n": "^7.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "nuxt",
|
||||
|
@ -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({
|
||||
|
Loading…
Reference in New Issue
Block a user