diff --git a/koa-router/koa-router-tests.ts b/koa-router/koa-router-tests.ts index deaa7e083d..36d3e6c1c8 100644 --- a/koa-router/koa-router-tests.ts +++ b/koa-router/koa-router-tests.ts @@ -11,6 +11,9 @@ const router = new Router({ }); router + .param('id', function(id, ctx, next) { + next(); + }) .get('/', function (ctx, next) { ctx.body = 'Hello World!'; }) @@ -23,7 +26,7 @@ router .del('/users/:id', function (ctx, next) { // ... }); - + router.get('user', '/users/:id', function (ctx, next) { ctx.body = "sdsd"; }); diff --git a/koa-router/koa-router.d.ts b/koa-router/koa-router.d.ts index d289657c84..25ec962dad 100644 --- a/koa-router/koa-router.d.ts +++ b/koa-router/koa-router.d.ts @@ -30,7 +30,7 @@ declare module "koa-router" { export interface IRouterOptions { /** - * Router prefixes + * Router prefixes */ prefix?: string; /** @@ -52,6 +52,10 @@ declare module "koa-router" { (ctx: Router.IRouterContext, next?: () => any): any; } + export interface IParamMiddleware { + (param: string, ctx: Router.IRouterContext, next?: () => any): any; + } + export interface IRouterAllowedMethodsOptions { /** * throw error instead of setting status and header @@ -141,13 +145,13 @@ declare module "koa-router" { */ get(name: string, path: string, ...middleware: Array): Router; get(path: string, ...middleware: Array): Router; - + /** * HTTP post method */ post(name: string, path: string, ...middleware: Array): Router; post(path: string, ...middleware: Array): Router; - + /** * HTTP put method */ @@ -214,7 +218,7 @@ declare module "koa-router" { /** * Redirect `source` to `destination` URL with optional 30x status `code`. - * + * * Both `source` and `destination` can be route names. */ redirect(source: string, destination: string, code?: number): Router; @@ -245,7 +249,7 @@ declare module "koa-router" { /** * Run middleware for named route parameters. Useful for auto-loading or validation. */ - param(param: string, middleware: Router.IMiddleware): Router; + param(param: string, middleware: Router.IParamMiddleware): Router; /** * Generate URL from url pattern and given `params`.