React Router: ReactRouterContext
Functions, types, and exports for React Router: ReactRouterContext.
Page outline
The request context a route module receives in its loader, action, or middleware.
import type { ReactRouterContext } from "@palamedes/react-router"
type ReactRouterContext = Readonly<RouterContextProvider>;
constructor
Create a new RouterContextProvider instance
constructor(init?: Map<RouterContext, unknown>)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
init | Map<RouterContext, unknown> | No | An optional initial context map to populate the provider with |
get
Access a value from the context. If no value has been set for the context,
it will return the context's defaultValue if provided, or throw an error
if no defaultValue was set.
get<T>(context: RouterContext<T>): T
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
context | RouterContext<T> | Yes | The context to get the value for |
Returns
T
The value for the context, or the context's defaultValue if no
value was set
set
Set a value for the context. If the context already has a value set, this will overwrite it.
set<C extends RouterContext>(context: C, value: C extends RouterContext<infer T> ? T : never): void
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
context | C | Yes | The context to set the value for |
value | C extends RouterContext<infer T> ? T : never | Yes | The value to set for the context |
Returns
void
{void}
Last updated: November 1, 2026