Skip to content

Types

Type definitions for the reactpy-router package.

Classes:

  • CompiledRoute –

    A protocol for a compiled route that can be matched against a path.

  • ConversionInfo –

    A TypedDict that holds information about a conversion type.

  • Resolver –

    Compile a route into a resolver that can be matched against a given path.

  • Route –

    A class representing a route that can be matched against a path.

  • RouteState –

    Represents the state of a route in the application.

  • Router –

    Return a component that renders the matching route(s).

Attributes:

  • ConversionFunc (TypeAlias) –

    A function that converts a string to a specific type.

  • ConverterMapping (TypeAlias) –

    A mapping of conversion types to their respective functions.

  • RouteType –

    A type variable for Route.

  • RouteType_contra –

    A contravariant type variable for Route.

reactpy_router.types.ConversionFunc: TypeAlias = Callable[[str], Any]

A function that converts a string to a specific type.

reactpy_router.types.ConverterMapping: TypeAlias = dict[str, ConversionFunc]

A mapping of conversion types to their respective functions.

reactpy_router.types.RouteType = TypeVar('RouteType', bound=Route)

A type variable for Route.

reactpy_router.types.RouteType_contra = TypeVar('RouteType_contra', bound=Route, contravariant=True)

A contravariant type variable for Route.

reactpy_router.types.CompiledRoute

A protocol for a compiled route that can be matched against a path.

Attributes:

  • key (Key) –

    A property that uniquely identifies this resolver.

Methods:

  • resolve –

    Return the path's associated element and path parameters or None.

reactpy_router.types.CompiledRoute.resolve(path)

Return the path's associated element and path parameters or None.

Parameters:

  • path (str) –

    The path to resolve.

Returns:

  • tuple[Any, dict[str, Any]] | None –

    A tuple containing the associated element and a dictionary of path parameters, or None if the path cannot be resolved.

reactpy_router.types.ConversionInfo

A TypedDict that holds information about a conversion type.

Attributes:

  • regex (str) –

    The regex to match the conversion type.

  • func (ConversionFunc) –

    The function to convert the matched string to the expected type.

reactpy_router.types.Resolver

Compile a route into a resolver that can be matched against a given path.

Methods:

  • __call__ –

    Compile a route into a resolver that can be matched against a given path.

reactpy_router.types.Resolver.__call__(route)

Compile a route into a resolver that can be matched against a given path.

Parameters:

Returns:

reactpy_router.types.Route

A class representing a route that can be matched against a path.

Attributes:

  • path (str) –

    The path to match against.

  • element (Any) –

    The element to render if the path matches.

  • routes (Sequence[Self]) –

    Child routes.

Methods:

  • __hash__ –

    Returns a hash value for the route based on its path, element, and child routes.

reactpy_router.types.RouteState

Represents the state of a route in the application.

Attributes:

  • set_location (Callable[[Location], None]) –

    A callable to set the location.

  • params (dict[str, Any]) –

    A dictionary containing route parameters.

reactpy_router.types.Router

Return a component that renders the matching route(s).

Methods:

  • __call__ –

    Process the given routes and return a component that renders the matching route(s).

reactpy_router.types.Router.__call__(*routes)

Process the given routes and return a component that renders the matching route(s).

Parameters:

  • *routes (RouteType_contra, default: () ) –

    A variable number of route arguments.

Returns:

  • Component –

    The resulting component after processing the routes.


Last update: October 17, 2024
Authors: Mark Bakhit