Package APIs

@i18n-micro/path-strategy

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

Shared strategy-based path and route name builder for Nuxt I18n Micro frontend routing.

Entry points: @i18n-micro/path-strategy, @i18n-micro/path-strategy/types.

@i18n-micro/path-strategy

Functions

createPathStrategy

function createPathStrategy(ctx: PathStrategyContext): PathStrategy

See PathStrategyContext · PathStrategy

Classes

DomainPathStrategy

The strategy of a build with locale domains (baseUrl). On a known host (ctx.domain) the locales of other domains are no URLs here, only link targets; on any other host the build config routes and every baseUrl locale is a link target. A class of its own: an app without domains does not ship it.

class DomainPathStrategy extends I18nPathStrategy {
  constructor(ctx: PathStrategyContext)
}
protected otherCodes
ReadonlySet<string>
Locales whose URLs are no page here but name one (another domain's): DomainPathStrategy.
protected createIndex
(records: ReturnType<RouterAdapter['getRoutes']>) => Index
Records keep every locale's prefix (other hosts link there); the default of this host links to its unprefixed record.
protected external
(locale: string, route: Target) => string | null
A route in locale as an absolute URL on another domain: DomainPathStrategy.
protected notFoundReason
(path: string) => string | null
switchLocaleRoute
(toLocale: string, route: ResolvedRouteLike, options?: SwitchLocaleOptions) => RouteLike | string
A link localeRoute made absolute reads as the page it shows, so it switches like any route.
localeRoute
(locale: string, routeOrPath: RouteLike | string) => RouteLike
An absolute link of a locale's own domain says where it goes (<i18n-link :to="$localeRoute(x, 'de')">). Any other absolute object stays a path: it can come from a request.
protected servedLocale
(route: ResolvedRouteLike, preferred: string) => string
A page restricted to some locales renders in one this host serves.
getClientRedirect
(currentPath: string, preferredLocale: string, options?: ClientRedirectOptions) => string | null
Where an unprefixed URL goes for the preferred locale (server plugin and client middleware), or null to stay. URLs with a locale prefix are never rewritten here.

See I18nPathStrategy · PathStrategyContext

I18nPathStrategy

class I18nPathStrategy {
  constructor(ctx: PathStrategyContext)
}

See PathStrategyContext

Types

ClientRedirectOptions

interface ClientRedirectOptions
switchPrefixed
boolean
autoDetectPath: '*': a URL already in another locale moves to the preferred one too (the same page in that locale), not only unprefixed URLs.

PathStrategy

The public surface, structural: the Nuxt template imports the built .mjs by path, and a class type with private members would not match the one TypeScript infers from that file.

type PathStrategy = {
  [K in keyof I18nPathStrategy]: I18nPathStrategy[K];
}

See I18nPathStrategy

PathStrategyContext

interface PathStrategyContext

ResolvedRouteLike

Resolved route (path and fullPath required).

interface ResolvedRouteLike extends RouteLike
name
string | symbol | null | undefined required
vue-router names may be symbols (RouteRecordNameGeneric).
path
string required
fullPath
string required
matched
RouteRecordLike[]
Matched records (vue-router routes have them): an unnamed route that matched is not a 404.

See RouteLike

RouteLike

Route-like shape (compatible with vue-router).

interface RouteLike
name
string | symbol | null
vue-router names may be symbols (RouteRecordNameGeneric).
path
string
params
Record<string, unknown>
query
Record<string, unknown>
hash
string
fullPath
string
meta
Record<string, unknown>
Route meta (vue-router merges the matched records'): i18nNoMeta marks an unlocalized page's disableMeta.

RouterAdapter

interface RouterAdapter
hasRoute
(name: string | symbol) => boolean required
resolve
(to: RouteLike | string) => ResolvedRouteLike required
getRoutes
() => RouteRecordLike[] required

RouteRecordLike

What path-strategy reads from a vue-router record (router.getRoutes()).

interface RouteRecordLike
name
string | symbol | null
path
string required
meta
Record<string, unknown>
redirect
unknown
aliasOf
{ path: string; }

SwitchLocaleOptions

interface SwitchLocaleOptions
i18nRouteParams
I18nRouteParams
named
boolean
Keep name and params on a route with an escape: for a caller that drops path, so the router encodes them.

Re-exports

Declared in another package of this repository and documented on its page.

@i18n-micro/path-strategy/types

Also exports, as @i18n-micro/path-strategy does: ClientRedirectOptions · PathStrategyContext · ResolvedRouteLike · RouteI18nMeta · RouteLike · RouterAdapter · RouteRecordLike · SwitchLocaleOptions.


Generated from the TypeScript sources and their JSDoc by pnpm run docs:generate. Back to all packages · Integration guides