useSeoMeta with i18n
Hello,
I use useSeoMeta with i18n
I have two languages : fr and en.
My meta works perfectly fine with https://domain.fr/fr and https://domain.fr/en, but fails with https://domain.fr.
How to treat the case when the root domain doesn't have the prefix yet when shared ?
Thanks 🙂
14 Replies
Hi @Omnislash. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To address the issue of handling SEO meta tags for the root domain without a language prefix while using i18n, you can use a combination of
useSeoMeta
and the i18n configuration. Here's how you can approach this:
1. First, ensure that your i18n configuration in nuxt.config.ts
is set up correctly to handle the root domain. You might want to use the defaultLocale
option:
2. In your app.vue
or the component where you're setting the SEO meta tags, you can use useSeoMeta
in combination with the useI18n
composable to dynamically set the meta tags based on the current locale:
This approach ensures that even when the root domain is accessed without a language prefix, appropriate meta tags are still set based on the default locale.
For more detailed information on using useSeoMeta
, you can refer to the Nuxt documentation on useSeoMeta.
Remember to test your implementation thoroughly to ensure it works as expected for all cases: the root domain, /fr
, and /en
routes.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@305772639438503936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@kapa.ai if it's access without prefix, what will be the value of locale.value ?
Let me check the knowledge base for you again. One moment! :books:
----------------------
When accessing the site without a language prefix, the value of
locale.value
will typically be the defaultLocale
specified in your i18n configuration.
According to the Nuxt i18n documentation, if you haven't set a specific locale and are accessing the root domain without a prefix, the defaultLocale
will be used.
For example, if your i18n configuration in nuxt.config.ts
looks like this:
Then, when accessing <https://domain.fr
> (without a language prefix), locale.value
would be 'en'.
However, it's important to note that the actual behavior can be influenced by other i18n settings, such as detectBrowserLanguage
or custom routing configurations. If you have these additional settings, they might affect the locale.value
when accessing the site without a prefix.
To be absolutely certain about the behavior in your specific setup, you could add a console log or use the Vue devtools to check the value of locale.value
when accessing your site without a language prefix.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@305772639438503936> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
So I don't see how the code Kapa gave me would work, since value will always be fr or en
If someone has an idea I'm listening ^^"
can you share some code
sure 🙂
perfect here :
https://launchbase.fr/en
not working here : https://launchbase.fr
My bad, I thought defaultLocale was to force a default language without considering the user browser... but it was not ^^"
Solved 🙂
Cool, not too sure why the second link didn't unfurl correctly
you're always server side redirecting it to
/fr
?I thought it was done by fallbackLocale: 'fr' in the i18n config, but most likely not ^^"
It seems it's done with defaultLocale: 'fr', now that I added it, it works nicely : https://launchbase.fr
yup looks good 👍