Guide
Route Rules
Applying route rules to localized routes.
Nuxt matches route rules by path and the keys of routeRules are not localized, a rule for /blog does not apply to /fr/blog or to a custom path such as /fr/le-blog.
Page rules
Rules defined in a page component with defineRouteRules() are applied to every localized route of that page.
This is the recommended way to set rules for localized pages since it is the only one that works with custom paths, the rules follow the page instead of a path.
nuxt.config.ts
export default defineNuxtConfig({
experimental: {
inlineRouteRules: true
}
})
pages/blog.vue
<script setup>
defineRouteRules({ ssr: false })
definePageMeta({
i18n: {
paths: {
fr: '/le-blog'
}
}
})
</script>
With the locales en (default), fr and nl and the 'prefix_except_default' strategy, the rule applies to /blog, /fr/le-blog and /nl/blog.
inlineRouteRules is an experimental Nuxt feature, its rules are applied to localized routes since Nuxt v4.1 and v3.19.We recommend using Nuxt v4.7 or later, earlier versions do not match pages with dynamic parameters exactly (a rule can be skipped or also apply to sibling pages) and can skip the rules of nested pages with custom paths.Rules in nuxt.config
Rules in
nuxt.config do not work with custom paths, a rule for /blog or /*/blog will not match /fr/le-blog. Use page rules for pages with custom paths, or add an entry for each localized path.Rules that are not tied to a single page, such as a rule for a whole section of your app, need an entry that matches the prefixed paths as well.
nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
// matches `/account/settings`
'/account/**': { ssr: false },
// matches `/fr/account/settings` and `/nl/account/settings`
'/*/account/**': { ssr: false }
}
})
The
* wildcard matches any single path segment and not only locale codes.