From 912d65eebf23437db55dcb4d127f8d2d6363aded Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Delafontaine?= Date: Mon, 16 Dec 2024 15:16:44 +0100 Subject: [PATCH] FIX bug instanciation de la locale au premier chargement --- components/common/HeaderCustom.vue | 3 +++ components/common/HeaderMobile.vue | 15 +++++++++++++++ pages/apropos.vue | 5 ++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/components/common/HeaderCustom.vue b/components/common/HeaderCustom.vue index e16fdd2..12f46f9 100644 --- a/components/common/HeaderCustom.vue +++ b/components/common/HeaderCustom.vue @@ -111,6 +111,9 @@ onMounted(() => { lang: locale.value, }, }) + } else { + locale.value = "fr"; + localStorage.setItem("language", locale.value); } }); diff --git a/components/common/HeaderMobile.vue b/components/common/HeaderMobile.vue index 8ebe0da..bb47d20 100644 --- a/components/common/HeaderMobile.vue +++ b/components/common/HeaderMobile.vue @@ -170,6 +170,21 @@ onBeforeMount(() => { isReady.value = true; }); +onMounted(() => { + if (localStorage.getItem("language")) { + locale.value = localStorage.getItem("language"); + + useHead({ + htmlAttrs: { + lang: locale.value, + }, + }) + } else { + locale.value = "fr"; + localStorage.setItem("language", locale.value); + } +}); + const props = defineProps({ type: { type: String, diff --git a/pages/apropos.vue b/pages/apropos.vue index 98d8de7..c5e1ce7 100644 --- a/pages/apropos.vue +++ b/pages/apropos.vue @@ -8,7 +8,10 @@ import { useRouter } from "nuxt/app"; const router = useRouter(); onMounted(() => { - router.push(localStorage.getItem("language") + '/apropos'); + router.push( + localStorage.getItem("language") + ? localStorage.getItem("language") + '/apropos' + : '/fr/apropos'); } ); \ No newline at end of file