React Router: ReactRouterI18n
Functions, types, and exports for React Router: ReactRouterI18n.
Page outline
import type { ReactRouterI18n } from "@palamedes/react-router"
type ReactRouterI18n<TLocale extends string = string> = {
/**
* Root route middleware. Export it from `app/root.tsx` as
* `export const middleware = [i18n.middleware]`; every loader, action, and
* document render below it then runs with the request's i18n instance.
*/
readonly middleware: MiddlewareFunction<Response>;
/**
* A complete streaming server entry. Use it as the default export of
* `app/entry.server.tsx`. It renders inside the request scope, provides
* `useDocumentLocale()` and `useCatalogAvailable()` with the document's
* state, and adds the locale's `<html lang>`,
* catalog import map, and readiness script to the document.
*/
readonly handleRequest: ReactRouterHandleRequest;
/** The locale the middleware resolved for this request. */
getLocale(context: ReactRouterContext): TLocale;
/** Custom entries: run `work` inside the request's i18n scope. */
run<Result>(request: Request, context: ReactRouterContext, work: () => Result | Promise<Result>): Promise<Result>;
/**
* Custom entries: the document transform for the request's locale. It sets
* `<html lang>` and, in production, adds the locale's import map.
*/
createDocumentTransform(request: Request, context: ReactRouterContext): Promise<Transform>;
/** The adapter's server i18n scope, created once per `createReactRouterI18n()` call. */
readonly scope: ServerI18nScope<I18nInstance>;
};
Properties
| Name | Type | Required | Description |
|---|---|---|---|
middleware | MiddlewareFunction<Response> | Yes | Readonly. Root route middleware. Export it from app/root.tsx asexport const middleware = [i18n.middleware]; every loader, action, anddocument render below it then runs with the request's i18n instance. |
handleRequest | ReactRouterHandleRequest | Yes | Readonly. A complete streaming server entry. Use it as the default export ofapp/entry.server.tsx. It renders inside the request scope, providesuseDocumentLocale() and useCatalogAvailable() with the document'sstate, and adds the locale's <html lang>,catalog import map, and readiness script to the document. |
scope | ServerI18nScope<I18nInstance> | Yes | Readonly. The adapter's server i18n scope, created once per createReactRouterI18n() call. |
getLocale
The locale the middleware resolved for this request.
getLocale(context: ReactRouterContext): TLocale
Parameters
| Name | Type | Required |
|---|---|---|
context | ReactRouterContext | Yes |
Returns
TLocale
run
Custom entries: run work inside the request's i18n scope.
run<Result>(request: Request, context: ReactRouterContext, work: () => Result | Promise<Result>): Promise<Result>
Parameters
| Name | Type | Required |
|---|---|---|
request | Request | Yes |
context | ReactRouterContext | Yes |
work | () => Result | Promise<Result> | Yes |
Returns
Promise<Result>
createDocumentTransform
Custom entries: the document transform for the request's locale. It sets
<html lang> and, in production, adds the locale's import map.
createDocumentTransform(request: Request, context: ReactRouterContext): Promise<Transform>
Parameters
| Name | Type | Required |
|---|---|---|
request | Request | Yes |
context | ReactRouterContext | Yes |
Returns
Promise<Transform>
Last updated: November 1, 2026