Package APIs

@i18n-micro/route-strategy

Exported API of @i18n-micro/route-strategy, generated from the source.

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)
}

See RouteGeneratorOptions

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> = {},
  )
}
get
(fullPath: string, name: string | undefined) => Rule | undefined
allowedLocales
(fullPath: string, name: string | undefined) => string[] | undefined
Locales a page may be served in, or undefined when it is not restricted.
disableMeta
(fullPath: string, name: string | undefined) => NoMeta | undefined
$defineI18nRoute({ disableMeta }): SEO tags off for the page (every locale, or the listed ones).
customKeysUnder
(base: string, locale: string) => string[]
Keys of the pages at or under base (a route key) with a custom path in locale: where a wildcard rule's pages live.
customPath
(fullPath: string, locale: string) => string | undefined
Custom path of a top-level path for a locale (nitro: prerender and routeRules).

See GlobalLocaleRoutes · Locale

Types

GenerateOptions

interface GenerateOptions

RouteGeneratorOptions

interface RouteGeneratorOptions

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