Interface RouteOptions<Params, Data, Context>

Options of a Route.

interface RouteOptions<Params, Data, Context> {
    component?: ComponentType;
    errorComponent?: ComponentType;
    isCaseSensitive?: boolean;
    lazyComponent?: (() => PromiseLike<{
        default: ComponentType;
    }>);
    loader?: ((params: Params, context: Context) => Data | PromiseLike<Data>);
    loadingAppearance?: LoadingAppearance;
    loadingComponent?: ComponentType;
    notFoundComponent?: ComponentType;
    paramsAdapter?: ParamsAdapter<Params> | ((params: Dict) => Params);
    pathname?: string;
}

Type Parameters

  • Params

    Route params.

  • Data

    Data loaded by a route.

  • Context

    A context provided by a Router for a loader.

Properties

component?: ComponentType

A component that is rendered by a route.

If both component and lazyComponent are omitted then a route implicitly renders an Outlet.

errorComponent?: ComponentType

A component that is rendered when an error was thrown during route rendering.

isCaseSensitive?: boolean

If true then pathname is matched in a case-sensitive manner.

false
lazyComponent?: (() => PromiseLike<{
    default: ComponentType;
}>)

A lazy-loaded component that is rendered by a route. A component cached forever if a returned Promise is fulfilled.

() => import('./UserPage')
loader?: ((params: Params, context: Context) => Data | PromiseLike<Data>)

Loads data required to render a route.

Type declaration

loadingAppearance?: LoadingAppearance

What to render when lazyComponent or loader are being loaded.

"auto"
loadingComponent?: ComponentType

A component that is rendered when a lazyComponent or loader are being loaded. Render a skeleton or a spinner in this component to notify user that a new route is being loaded.

notFoundComponent?: ComponentType

A component that is rendered if notFound was called during route rendering.

paramsAdapter?: ParamsAdapter<Params> | ((params: Dict) => Params)

An adapter that can validate and transform params extracted from the Location.pathname and Location.searchParams.

Type declaration

pathname?: string

A URL pathname pattern.

Pattern can include params that conform :[A-Za-z$_][A-Za-z0-9$_]+. For example "/:userId".

Params match a whole segment and cannot be partial. For example, "/teams--:teamId" is invalid and would throw a SyntaxError, while "/teams/:teamId" is valid.

By default, a param matches a non-empty pathname segment. To make a param optional (so it can match an absent segment) follow it by a ? flag. For example: "/user/:userId?" matches both "/user" and "/user/37".

Static pathname segments can be optional as well: "/project/task?/:taskId".

By default, a param matches a single pathname segment. Follow a param with a * flag to make it match multiple segments. For example: "/:slug*" matches "/watch" and "/watch/a/movie". Such params are called wildcard params.

To make param both wildcard and optional, combine * and ? flags: "/:slug*?".

To use : as a character in a pathname pattern, replace it with an encoded representation: %3A.

"/"