@mojojs/core
    Preparing search index...

    Class Route

    Route class.

    Hierarchy (View Summary)

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

    The children of this route, used for nesting routes.

    customName: string | undefined = undefined

    Custom route name, if defined.

    defaultName: string | undefined = 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.

    • get parent(): Route | undefined

      The parent of this route.

      Returns Route | undefined

    • set parent(parent: Route | undefined): void

      Parameters

      • parent: Route | undefined

      Returns void

    • get root(): Router | undefined

      Return the Router object this route is a descendant of.

      Returns Router | undefined

    • set root(root: Router | undefined): void

      Parameters

      Returns void

    • Add a child to this route.

      Parameters

      Returns Route

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

      Parameters

      Returns Route

      // 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

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

      Parameters

      Returns Route

      // 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 this

    • Generate route matching only OPTIONS requests.

      Parameters

      Returns Route

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

      Parameters

      Returns Route

      // Route with destination
      route.patch('/user').to('User#update');

    post

    • post(...args: RouteArguments): Route

      Generate route matching only POST requests.

      Parameters

      Returns Route

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

      Parameters

      Returns Route

      // Route with destination
      route.put('/user').to('User#replace');
    • Generate route matching only QUERY requests.

      Parameters

      Returns Route

      // Route with destination
      route.query('/search').to('Search#index');
    • Remove route from parent.

      Returns this

    • 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 this

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

      Returns string

    • Set default parameters for this route.

      Parameters

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

      Returns this

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

      Parameters

      Returns Route

      // 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

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