Routing
Is not mandatory, but is possible to let the plugin manage redirects and URL prefixing passing the VueRouter instance to the plugin options.
Your installation then should look something like this:
import Vue from 'vue'
import VueI18nManager, { routeParser } from 'vue-i18n-manager'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
Vue.use(Vuex)
Vue.use(VueRouter)
const store = new Vuex.Store({ ... })
const router = new VueRouter({ ... })
Vue.use(VueI18nManager, { store, router })
From now on a lang
parameter needs to be passed every time a route changes.
routeParser
It's an helper function which modifies the routes tree before is added to the VueRouter instance.
import Vue from 'vue'
import VueI18nManager, { routeParser } from 'vue-i18n-manager'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
Vue.use(Vuex)
Vue.use(VueRouter)
const store = new Vuex.Store({ ... })
const router = new VueRouter({
routes: routeParser([
{ ... }
])
})
Vue.use(VueI18nManager, { store, router })
$localize
It's an helper method that allows to inject the current language in the route parameters.
Normally this is what it needs to be write:
<router-link :to="{ name: 'home', params: { lang: urlPrefix } }"></router-link>
the helper allows to just type this:
<router-link :to="$localize({ name: 'home' })"></router-link>