mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-07 09:22:27 +00:00
Merge pull request #2299 from CKGrafico/better-links
Update i18n example with better links
This commit is contained in:
commit
32e67c7481
@ -4,10 +4,10 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="Header__Title">Nuxt i18n</h1>
|
<h1 class="Header__Title">Nuxt i18n</h1>
|
||||||
<nav class="Header__Menu">
|
<nav class="Header__Menu">
|
||||||
<nuxt-link class="Header__Link" :to="path('/')" exact>
|
<nuxt-link class="Header__Link" :to="$i18n.path('')" exact>
|
||||||
{{ $t('links.home') }}
|
{{ $t('links.home') }}
|
||||||
</nuxt-link>
|
</nuxt-link>
|
||||||
<nuxt-link class="Header__Link" :to="path('/about')" exact>
|
<nuxt-link class="Header__Link" :to="$i18n.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>
|
||||||
@ -24,13 +24,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {}
|
||||||
methods: {
|
|
||||||
path(url) {
|
|
||||||
return (this.$i18n.locale === 'en' ? url : '/' + this.$i18n.locale + url)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -14,4 +14,12 @@ export default ({ app, store }) => {
|
|||||||
'fr': require('~/locales/fr.json')
|
'fr': require('~/locales/fr.json')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.i18n.path = (link) => {
|
||||||
|
if (app.i18n.locale === app.i18n.fallbackLocale) {
|
||||||
|
return `/${link}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return `/${app.i18n.locale}/${link}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user