i18n and route rules
I'm using the latest version of Nuxt + @nuxtjs/i18n configured with strategy: 'prefix_except_default' and recently noticed something odd - my route rules aren't being applied to prefixed paths. For example, routeRules: { '/foobar': { ssr: false } } only applies to /foobar, not the prefixed /fr/foobar path. It's relatively easy to work around by adding unique route rules for every language, for every path, but it does quickly multiply the number of route rules which is annoying.
I was just wondering - does anyone happen to know if this has always worked this way, or if it may be a newish bug? I've been running Nuxt + i18n in production with a half dozen languages for at least a year, but this is the first time I noticed the route rules only applying to the default language's (non-prefixed) path.
2 Replies
Hi @Surreal. 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 information provided in the knowledge sources, I don't have enough specific details to definitively answer whether this behavior has always worked this way or if it's a new bug. However, I can provide some relevant information and suggestions based on the available documentation.
The
routeRules
feature in Nuxt is described as experimental in the Nuxt Configuration documentation (https://nuxt.com/docs/api/nuxt-config#routerules-1). This means that its API and behavior may change in future updates.
Regarding i18n and route rules, there's no explicit mention of how they interact with prefixed paths in the provided knowledge sources. However, we can consider a few points:
1. The inlineRouteRules
experimental feature allows defining route rules at the page level using defineRouteRules
. As mentioned in the Nuxt documentation (https://nuxt.com/docs/api/nuxt-config#inlinerouterules), these rules are converted based on the path. For example, a rule defined in ~/pages/foo/bar.vue
will be applied to /foo/bar
requests.
2. The documentation doesn't mention how these rules interact with i18n prefixes, which aligns with your observation that the rules aren't being applied to prefixed paths.
3. As a workaround, you might consider using the inlineRouteRules
feature if it suits your use case. This way, you could define rules directly in your page components, which might apply more consistently across localized routes.
4. If you need to report this as a potential bug or get more clarification, the Nuxt documentation on reporting bugs (https://nuxt.com/docs/community/reporting-bugs#figure-out-what-the-cause-might-be) suggests trying to report the issue at the most relevant and specific place. In this case, it might be worth checking with the @nuxtjs/i18n
module maintainers or the Nuxt core team.
Given the experimental nature of routeRules
and the lack of specific documentation about its interaction with i18n prefixes, it's difficult to say whether this behavior is intentional or a bug. If this is causing significant issues in your project, I would recommend reaching out to the Nuxt or @nuxtjs/i18n
community for more specific guidance or to report a potential bug.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@390675691667980293> Kapa.ai is still learning and improving, please let me know how I did by reacting below.