Interface IRouter

interface IRouter {
    all: IRouterMatcher<IRouter, "all">;
    checkout: IRouterMatcher<IRouter, any>;
    connect: IRouterMatcher<IRouter, any>;
    copy: IRouterMatcher<IRouter, any>;
    delete: IRouterMatcher<IRouter, "delete">;
    get: IRouterMatcher<IRouter, "get">;
    head: IRouterMatcher<IRouter, "head">;
    link: IRouterMatcher<IRouter, any>;
    lock: IRouterMatcher<IRouter, any>;
    m-search: IRouterMatcher<IRouter, any>;
    merge: IRouterMatcher<IRouter, any>;
    mkactivity: IRouterMatcher<IRouter, any>;
    mkcol: IRouterMatcher<IRouter, any>;
    move: IRouterMatcher<IRouter, any>;
    notify: IRouterMatcher<IRouter, any>;
    options: IRouterMatcher<IRouter, "options">;
    patch: IRouterMatcher<IRouter, "patch">;
    post: IRouterMatcher<IRouter, "post">;
    propfind: IRouterMatcher<IRouter, any>;
    proppatch: IRouterMatcher<IRouter, any>;
    purge: IRouterMatcher<IRouter, any>;
    put: IRouterMatcher<IRouter, "put">;
    report: IRouterMatcher<IRouter, any>;
    search: IRouterMatcher<IRouter, any>;
    stack: ILayer[];
    subscribe: IRouterMatcher<IRouter, any>;
    trace: IRouterMatcher<IRouter, any>;
    unlink: IRouterMatcher<IRouter, any>;
    unlock: IRouterMatcher<IRouter, any>;
    unsubscribe: IRouterMatcher<IRouter, any>;
    use: IRouterHandler<IRouter, string> & IRouterMatcher<IRouter, any>;
    param(name, handler): this;
    param(callback): this;
    route<T>(prefix): IRoute<T>;
    route(prefix): IRoute<string>;
    (req, res, next): void;
}

Hierarchy (view full)

Properties

all: IRouterMatcher<IRouter, "all">

Special-cased "all" method, applying the given route path, middleware, and callback to every HTTP method.

checkout: IRouterMatcher<IRouter, any>
connect: IRouterMatcher<IRouter, any>
delete: IRouterMatcher<IRouter, "delete">
get: IRouterMatcher<IRouter, "get">
head: IRouterMatcher<IRouter, "head">
m-search: IRouterMatcher<IRouter, any>
merge: IRouterMatcher<IRouter, any>
mkactivity: IRouterMatcher<IRouter, any>
mkcol: IRouterMatcher<IRouter, any>
notify: IRouterMatcher<IRouter, any>
options: IRouterMatcher<IRouter, "options">
patch: IRouterMatcher<IRouter, "patch">
post: IRouterMatcher<IRouter, "post">
propfind: IRouterMatcher<IRouter, any>
proppatch: IRouterMatcher<IRouter, any>
purge: IRouterMatcher<IRouter, any>
put: IRouterMatcher<IRouter, "put">
report: IRouterMatcher<IRouter, any>
search: IRouterMatcher<IRouter, any>
stack: ILayer[]

Stack of configured routes

subscribe: IRouterMatcher<IRouter, any>
trace: IRouterMatcher<IRouter, any>
unlink: IRouterMatcher<IRouter, any>
unlock: IRouterMatcher<IRouter, any>
unsubscribe: IRouterMatcher<IRouter, any>

Methods

  • Map the given param placeholder name(s) to the given callback(s).

    Parameter mapping is used to provide pre-conditions to routes which use normalized placeholders. For example a :user_id parameter could automatically load a user's information from the database without any additional code,

    The callback uses the samesignature as middleware, the only differencing being that the value of the placeholder is passed, in this case the id of the user. Once the next() function is invoked, just like middleware it will continue on to execute the route, or subsequent parameter functions.

     app.param('user_id', function(req, res, next, id){
    User.find(id, function(err, user){
    if (err) {
    next(err);
    } else if (user) {
    req.user = user;
    next();
    } else {
    next(new Error('failed to load user'));
    }
    });
    });

    Parameters

    Returns this

  • Alternatively, you can pass only a callback, in which case you have the opportunity to alter the app.param()

    Parameters

    • callback: Object

    Returns this

    Deprecated

    since version 4.11

  • Type Parameters

    • T extends string

    Parameters

    • prefix: T

    Returns IRoute<T>

  • Parameters

    Returns IRoute<string>