I've been integrating nuxt-i18n into one of my projects to enable multiple languages. It all works fine, but when I switch language while filling in a form, all data from the page is lost.
So, I created a form and use v-model to bind the data to the page's data object.
<div class="form-group">
<label for="username">{{ $t('form.username') }}</label>
<input v-model="user.username" type="username" class="form-control" id="username" />
</div>
This is the page's data object
data: () => {
return {
user: {
username: ''
}
}
So when I type a username in the field, the model is updated, as I expect. But as soon as I switch the language from that page, the data is lost as soon as the chosen language has been set.
This is how I switch the language when clicking, for example, the dutch flag icon.
switchLocalePath(locale.code) // local.code is 'nl' in this case
When the user switches the language, the slug should also update. The code below shows the settings for the i18n package in my nuxt.config.js file.
modules: [
['nuxt-i18n', {
locales: [
{
code: 'en',
iso: 'en-US',
name: 'English'
},
{
code: 'nl',
iso: 'nl-NL',
name: 'Nederlands'
}
],
defaultLocale: 'nl',
parsePages: false,
pages: {
'account/register': {
en: '/account/register',
nl: '/account/registreren'
},
'account/index': {
en: '/account/login',
nl: '/account/inloggen'
}
},
vueI18n: {
fallbackLocale: 'nl',
messages: { nl, en }
}
}],
]
The actual question
So almost everything works just as I expect. But every time I change the language, the page's data object is cleared (It doesn't seem like the page actually reloads). So when filling in a form, then changing the language before submitting, all data is lost.
How can I make sure, if possible, that all data presists when toggling the language?
Thanks in advance!