🐛 Fixes issue with async data and routes
This commit is contained in:
parent
205ec7f2bd
commit
51e465ce43
|
@ -33,7 +33,7 @@
|
|||
import { GA_COOKIE_NAME } from '@/config/analytics'
|
||||
import { SUPPORTED_LOCALES } from '@/config'
|
||||
import { setCookie, getCookie } from '@/helper/cookies'
|
||||
import { getUserLanguage, getTranslatedUrl } from '@/i18n/helper'
|
||||
import { getCountryByIP, getTranslatedUrl } from '@/i18n/helper'
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
|
@ -120,8 +120,8 @@
|
|||
},
|
||||
|
||||
async created () {
|
||||
const { country } = await getUserLanguage()
|
||||
this.userCountry = country
|
||||
const ipData = await getCountryByIP()
|
||||
this.userCountry = ipData.country_code
|
||||
},
|
||||
|
||||
methods: {
|
||||
|
|
|
@ -18,21 +18,17 @@ export const setCurrentLocale = (locale) => {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getUserLanguage () {
|
||||
export function getUserLanguage () {
|
||||
const lang = (
|
||||
window.navigator.language ||
|
||||
window.navigator.userLanguage ||
|
||||
DEFAULT_LOCALE
|
||||
)
|
||||
const ipData = await getCountryByIP()
|
||||
return {
|
||||
language: lang.split('-')[0],
|
||||
country: ipData.country_code || lang.split('-')[1].toLowerCase()
|
||||
}
|
||||
return lang.split('-')[0]
|
||||
}
|
||||
|
||||
export function getUserSupportedLanguage () {
|
||||
const { language } = getUserLanguage()
|
||||
const language = getUserLanguage()
|
||||
return isLangSupported(language)
|
||||
? language
|
||||
: DEFAULT_LOCALE
|
||||
|
|
|
@ -8,11 +8,10 @@ export function getPageTitle (data = {}) {
|
|||
: title
|
||||
}
|
||||
|
||||
export async function beforeEnter (to, from, next) {
|
||||
export function beforeEnter (to, from, next) {
|
||||
const lang = to.params.locale
|
||||
if (!i18n.isLangSupported(lang)) {
|
||||
const { language } = await i18n.getUserLanguage()
|
||||
return next(language)
|
||||
return next(i18n.getUserLanguage())
|
||||
}
|
||||
|
||||
i18n.setCurrentLocale(lang)
|
||||
|
|
Loading…
Reference in a new issue