Route class.

Hierarchy

Constructors

Properties

_parent: undefined | WeakRef<Route> = undefined
_root: undefined | WeakRef<Router> = undefined
children: Route[] = []

The children of this route, used for nesting routes.

customName: undefined | string = undefined

Custom route name, if defined.

defaultName: undefined | string = undefined

Default route name.

methods: string[] = []

Restrict HTTP methods this route is allowed to handle, defaults to no restrictions.

pattern: Pattern = ...

Pattern for this route.

requirements: Record<string, any>[] = []

Activate conditions for this route.

underRoute: boolean = false

Allow under semantics for this route.

websocketRoute: boolean = false

Activate websocket semantics for this route.

Accessors

  • get parent(): undefined | Route
  • The parent of this route.

    Returns undefined | Route

  • set parent(parent): void
  • Parameters

    • parent: undefined | Route

    Returns void

  • get root(): undefined | Router
  • Return the Router object this route is a descendant of.

    Returns undefined | Router

  • set root(root): void
  • Parameters

    Returns void

Methods

  • Add a child to this route.

    Parameters

    Returns Route

  • Generate route matching any of the listed HTTP request methods or all.

    Parameters

    Returns Route

    Example

    // Route with pattern and destination
    route.any('/user').to('User#whatever');

    // Route with HTTP methods, pattern, restrictive placeholders and destination
    route.any(['DELETE', 'PUT'], '/:foo', {foo: /\w+/}).to('Foo#bar');

    // Route with pattern, name and destination
    route.any('/:foo').name('foo_route').to('Foo#bar');

    // Route with pattern, condition and destination
    route.any('/').requires({agent: /Firefox/}).to('Foo#bar');

    // Route with pattern and a closure as destination
    route.any('/:foo', async ctx => ctx.render({text: 'Hello World!'}));
  • Generate route matching only DELETE requests.

    Parameters

    Returns Route

    Example

    // Route with destination
    route.delete('/user').to('User#remove');
  • Generate route matching only GET requests.

    Parameters

    Returns Route

    Example

    // Route with destination
    route.get('/user').to('User#show');
  • Check if this route has a WebSocket ancestor and cache the result for future checks.

    Returns boolean

  • Check if this route qualifies as an endpoint.

    Returns boolean

  • The name of this route, defaults to an automatically generated name based on the route pattern. Note that the name current is reserved for referring to the current route.

    Parameters

    • name: string

    Returns Route

  • Generate route matching only OPTIONS requests.

    Parameters

    Returns Route

    Example

    // Route with destination
    route.options('/user').to('User#overview');
  • Generate route matching only PATCH requests.

    Parameters

    Returns Route

    Example

    // Route with destination
    route.patch('/user').to('User#update');
  • Generate route matching only POST requests.

    Parameters

    Returns Route

    Example

    // Route with destination
    route.post('/user').to('User#create');
  • Generate route matching only PUT requests.

    Parameters

    Returns Route

    Example

    // Route with destination
    route.put('/user').to('User#replace');
  • Remove route from parent.

    Returns Route

  • Render route with parameters into a path.

    Parameters

    • values: {} = {}

      Returns string

    • Activate conditions for this route. Note that this automatically disables the routing cache, since conditions are too complex for caching.

      Parameters

      • condition: string
      • requirement: Record<string, any>

      Returns Route

    • Suggested HTTP method for reaching this route, GET and POST are preferred.

      Returns string

    • Set default parameters for this route.

      Parameters

      • Rest ...targets: (string | Record<string, any> | MojoAction)[]

      Returns Route

    • Generate route for a nested route with its own intermediate destination.

      Parameters

      Returns Route

      Example

      // Intermediate destination and prefix shared between two routes
      const auth = app.under('/user').to('User#auth');
      auth.get('/show').to('User#show');
      auth.post('/create').to('User#create');
    • Generate route matching only WebSocket handshake requests.

      Parameters

      Returns Route

      Example

      // Route with destination
      app.websocket('/echo').to('Example#echo');

    Generated using TypeDoc