@i18n-micro/route-strategy
Locale-aware route generator for Nuxt i18n micro
import { … } from '@i18n-micro/route-strategy'
Functions
generateRoutes
function generateRoutes(
pages: NuxtPage[],
options: GenerateOptions,
localizedPaths?: LocalizedPaths,
): NuxtPage[]
See GenerateOptions
isLocaleAllowedForUnlocalizedRoute
Whether localeCode may serve this path given $defineI18nRoute locales / routeLocales.
Unrestricted paths (and restrictions naming no known locale) allow every locale.
function isLocaleAllowedForUnlocalizedRoute(
routeLocales: Record<string, string[]>,
locales: Locale[],
routePath: string,
localeCode: string,
): boolean
See Locale
localeMatcherSource
The pattern of a customRegexMatcher: /re/ and re alike, and a RegExp loses its flags, as in the route and in path-strategy.
function localeMatcherSource(matcher: string | RegExp): string
localesOutsideMatcher
The codes matcher cannot route. The whole code must match, without flags: what the router and path-strategy will do.
function localesOutsideMatcher(
codes: readonly string[],
matcher: string | RegExp,
): string[]
nameOfPath
The name Nuxt's scanner would give the path: /a/:id() -> a-id.
function nameOfPath(fullPath: string): string
normalizePath
a//b/ -> a/b; '' and . -> ''.
function normalizePath(routePath: string): string
normalizeRouteKey
File-path and Nuxt forms of a route path to the vue-router form rules are keyed and written in:
[...slug] -> :slug(.*)*, [[page]] -> :page?, [id] -> :id, :id() -> :id
(non-empty matchers such as :id(\d+) stay).
function normalizeRouteKey(key: string): string
pageNames
Route names of the pages, nested ones included.
function pageNames(pages: NuxtPage[]): string[]
routeKey
Lookup key of a route path or name: normalized, without the leading slash (/ for the root).
function routeKey(routePathOrName: string): string
Classes
RouteGenerator
class RouteGenerator {
constructor(options: RouteGeneratorOptions)
}
pages (in place, as Nuxt's pages:resolved hook expects) with the localized routes./about + de -> /de/ueber-uns. Paths the pages do not have (wildcards, API
routes) only get the prefix./blog/**) also reaches the
pages under it that moved to a custom path, and only those: /de/artikel/:slug for /artikel/[slug].Rules
globalLocaleRoutes / $defineI18nRoute rules and routeLocales restrictions, keyed once by
routeKey so about/team and /about/team are looked up the same way everywhere. A page is
looked up by its full original path first (about-team / /about-team for a top-level page,
the form without the slash winning), then by its route name, which only keys written without a
leading slash can be.
class Rules {
constructor(
globalLocaleRoutes: GlobalLocaleRoutes = {},
routeLocales: Record<string, string[]> = {},
locales: Locale[] = [],
routeDisableMeta: Record<string, NoMeta> = {},
)
}
$defineI18nRoute({ disableMeta }): SEO tags off for the page (every locale, or the listed ones).base (a route key) with a custom path in locale: where a wildcard rule's pages live.See GlobalLocaleRoutes · Locale
Types
GenerateOptions
interface GenerateOptions
false: no redirect records either, a page's original URL under prefix is a 404 like any unprefixed one.RouteGeneratorOptions
interface RouteGeneratorOptions
$defineI18nRoute ones merged in (config wins).$defineI18nRoute({ disableMeta }) by page path: baked into meta.i18n.noMeta.redirects: false of the module: no redirect records._locales by default): pages under it stay unlocalized.blog.vue next to blog/): a relative custom value of a child hangs off them.Re-exports
Declared in another package of this repository and documented on its page.
Generated from the TypeScript sources and their JSDoc by pnpm run docs:generate.
Back to all packages · Integration guides