Class Router<T, R, C>

The main class that creates a router instance.

Type Parameters

Constructors

Properties

Methods

Constructors

Properties

baseURL: URL

The base URL against which all routes will be resolved. This option is designed for applications hosted on URLs like the following:

https://example.com/path/to/my/root

It doesn't consider URLs from the <base> tag. If you use it, you should provide the base URL manually.

routes: readonly Route<T, R, C>[]

A list of routes that are used to resolve the URL.

Methods

  • Resolves the provided path based on the established routes.

    Parameters

    • path: string | URL

      The path to be resolved. It can be either an absolute URL or a string path relative to the RouterOptions.baseURL.

    Returns Promise<undefined | null | T>

  • Resolves the provided path based on the established routes.

    Parameters

    • path: string | URL

      The path to be resolved. It can be either an absolute URL or a string path relative to the RouterOptions.baseURL.

    • context: C extends EmptyObject
          ? never
          : C

      Any data that needs to be sent to Route.action. The type of this parameter should match the C type parameter of the Route. If C is not provided or is equal to EmptyObject, setting this parameter is forbidden.

    Returns Promise<undefined | null | T>