remove 2 arg version, Object to any

This commit is contained in:
Guillaume Mayer
2018-10-24 03:33:15 -03:00
parent bbdf8ce9db
commit 098ee2ffeb
2 changed files with 21 additions and 19 deletions
+10 -12
View File
@@ -263,26 +263,24 @@ declare class Router {
/**
* Generate URL for route. Takes either map of named `params` or series of
* arguments (for regular expression routes)
*/
url(name: string, params: Object): string;
url(name: string, params: Object): Error;
/**
* Generate URL for route with query part.
*
* Takes either map of named `params` or series of
* arguments (for regular expression routes)
* router = new Router();
* router.get('user', "/users/:id", ...
*
* Query is generated from `options` argument:
* router.url('user', { id: 3 });
* // => "/users/3"
*
* Query can be generated from third argument:
*
* router.url('user', { id: 3 }, { query: { limit: 1 } });
* // => "/users/3?limit=1"
*
*
* router.url('user', { id: 3 }, { query: "limit=1" });
* // => "/users/3?limit=1"
*
*/
url(name: string, params: Object, options?: Router.IUrlOptionsQuery): string;
url(name: string, params: Object, options?: Router.IUrlOptionsQuery): Error;
url(name: string, params: any, options?: Router.IUrlOptionsQuery): string;
url(name: string, params: any, options?: Router.IUrlOptionsQuery): Error;
/**
* Match given `path` and return corresponding routes.
+11 -7
View File
@@ -14,16 +14,20 @@ router
.get('/', function (ctx, next) {
ctx.body = 'Hello World!';
})
.get('/users/:id', function (ctx, next) {
ctx.body = ctx.router.url('user-accounts', { id: ctx.params.id })
.get('user', '/users/:id', function (ctx, next) {
ctx.body = {
test1: ctx.router.url('user-accounts', { id: ctx.params.id }),
test2: ctx.router.url('user-accounts', ctx.params.id),
test3: ctx.router.url('user-accounts', [ctx.params.id]),
}
})
.get('user-accounts', '/users/:id/accounts', function (ctx, next) {
ctx.body = {
test1: ctx.router.url('users', { id: 3 }, { query: { limit: 1 } }),
test2: ctx.router.url('users', { id: 3 }, { query: "limit=1" }),
test3: ctx.router.url('users', 3, { query: { limit: 1 } }),
test4: ctx.router.url('users', [3], { query: "limit=1" }),
test5: ctx.router.url('users', ["3"], { query: { limit: "1" } }),
test1: ctx.router.url('user', { id: 3 }, { query: { limit: 1 } }),
test2: ctx.router.url('user', { id: 3 }, { query: "limit=1" }),
test3: ctx.router.url('user', 3, { query: { limit: 1 } }),
test4: ctx.router.url('user', [3], { query: "limit=1" }),
test5: ctx.router.url('user', ["3"], { query: { limit: "1" } }),
}
})
.post('/users', function (ctx, next) {