Custom strategy for page with i18n
hi, i got a question i am updating my saas and implementing i18n
how can i make that my marketing page use the
prefix_except_default strategy
with
/about # in normal
/fr/a-propos # in locale fr
but in dashboard route and all his children i only want
/dashboard # in english and french but the the when i swich locale the text locale change but their isnt any prefix in the page
currently got this config
i18n: {
defaultLocale: 'en',
baseUrl: 'https://domain.com',
strategy: 'prefix_except_default',
detectBrowserLanguage: {
redirectOn: 'root',
},
locales: [
{
code: 'en',
name: 'English',
files: generateLocaleFiles('en', listOfSections),
}, {
code: 'fr',
name: 'Français',
files: generateLocaleFiles('fr', listOfSections),
},
],
},
10 Replies
Hi @magius. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the knowledge sources, Nuxt i18n’s routing strategies (like
Dynamic routing in Nuxt 3 with I18n ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
prefix_except_default
) apply globally to all routes by default. This means that, out of the box, you cannot natively apply different i18n strategies to different sections of your app (e.g., marketing pages vs. dashboard pages) using only the standard configuration.
However, Nuxt i18n does support custom route mapping via the pages
and customRoutes
options. This allows you to define specific paths for each locale on a per-page basis. For your use case, you can:
- Use prefix_except_default
globally.
- For your dashboard routes, define custom routes in the pages
option so that both English and French versions do not have a locale prefix (i.e., /dashboard
for both).
Here’s an example of how you might configure this:
With this setup:
- /about
(English, default) and /fr/a-propos
(French) will work as you want.
- /dashboard
will be used for both English and French, and switching the locale will only change the content, not the URL prefix.
Note: You must define all dashboard-related routes in the pages
mapping to ensure they are not prefixed in any locale. This approach is supported by the Nuxt i18n module’s custom route mapping feature, as shown in the documentation and examples from the knowledge sources Dynamic routing in Nuxt 3 with I18n.
If you need more advanced or dynamic control, you may need to handle some logic in your middleware or page components, but the above method should cover your described use case.
If you need a reference for the pages
and customRoutes
options, see the example in the knowledge sources:Dynamic routing in Nuxt 3 with I18n ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
<@210060988429500416> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
with this config i still obtain /dashboard and fr/dashboard
@kapa.ai
Let me check the knowledge base for you again. One moment! :books:
Sorry @magius, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist:
Perhaps try again in 15mins?
with this config i still obtain /dashboard and fr/dashboard @kapa.ai
Let me check the knowledge base for you again. One moment! :books:
----------------------
With the current knowledge sources, the Nuxt i18n module’s
Based on the available documentation and examples, it is not possible to have a global
customRoutes
and pages
options allow you to map specific routes to custom paths per locale. However, according to the example provided in Dynamic routing in Nuxt 3 with I18n, if you want both English and French to use /dashboard
(with no prefix for either), your pages
config should look like this:
If you are still seeing /fr/dashboard
for the French locale, it suggests that the global strategy: 'prefix_except_default'
is still being applied to all routes, and the custom route mapping is not overriding it for the dashboard route as you expect.
The knowledge sources do not provide a way to fully disable the prefix for a specific route when using prefix_except_default
globally. The custom route mapping allows you to customize the path, but the prefix strategy may still apply. There is no documented way in the sources to have a mixed strategy (prefix for some routes, no prefix for others) purely through configuration.
Summary:Based on the available documentation and examples, it is not possible to have a global
prefix_except_default
strategy and also have a specific route (like /dashboard
) with no prefix in all locales using only the Nuxt i18n configuration options. The knowledge sources do not describe a solution for this scenario.
If you need this behavior, you may need to look for workarounds or custom logic outside of the standard configuration, but the knowledge sources do not provide guidance on this.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@210060988429500416> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
and if i do
@kapa.ai
Let me check the knowledge base for you again. One moment! :books:
----------------------
I'm sorry, but the knowledge sources do not contain any information about using
dashboard: false
in the pages
configuration for Nuxt i18n. There is no documentation or example in the provided sources that describes this approach or its effects.
Based on the available sources, the pages
option is used to map route names to custom paths per locale, but there is no mention of using false
as a value to disable or exclude a route from i18n routing. Therefore, I cannot confirm whether this would work or what the outcome would be.
If you need to exclude a route from i18n handling, the knowledge sources do not provide a documented method for doing so.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@210060988429500416> Kapa.ai is still learning and improving, please let me know how I did by reacting below.