@eggjs/router 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +24 -1
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -32,12 +32,13 @@ Router core component for [Egg.js](https://github.com/eggjs).
32
32
  <a name="exp_module_egg-router--Router"></a>
33
33
 
34
34
  ### Router ⏏
35
+
35
36
  **Kind**: Exported class
36
37
  <a name="new_module_egg-router--Router_new"></a>
37
38
 
38
39
  #### new Router([opts])
39
- Create a new router.
40
40
 
41
+ Create a new router.
41
42
 
42
43
  | Param | Type | Description |
43
44
  | --- | --- | --- |
@@ -62,9 +63,11 @@ app
62
63
  .use(router.routes())
63
64
  .use(router.allowedMethods());
64
65
  ```
66
+
65
67
  <a name="module_egg-router--Router+get|put|post|patch|delete|del"></a>
66
68
 
67
69
  #### router.get|put|post|patch|delete|del ⇒ <code>Router</code>
70
+
68
71
  Create `router.verb()` methods, where *verb* is one of the HTTP verbs such
69
72
  as `router.get()` or `router.post()`.
70
73
 
@@ -188,12 +191,14 @@ used to convert paths to regular expressions.
188
191
  <a name="module_egg-router--Router+routes"></a>
189
192
 
190
193
  #### router.routes ⇒ <code>function</code>
194
+
191
195
  Returns router middleware which dispatches a route matching the request.
192
196
 
193
197
  **Kind**: instance property of <code>[Router](#exp_module_egg-router--Router)</code>
194
198
  <a name="module_egg-router--Router+use"></a>
195
199
 
196
200
  #### router.use([path], middleware) ⇒ <code>Router</code>
201
+
197
202
  Use given middleware.
198
203
 
199
204
  Middleware run in the order they are defined by `.use()`. They are invoked
@@ -209,6 +214,7 @@ sequentially, requests start at the first middleware and work their way
209
214
  | [...] | <code>function</code> |
210
215
 
211
216
  **Example**
217
+
212
218
  ```javascript
213
219
  // session middleware will run before authorize
214
220
  router
@@ -223,9 +229,11 @@ router.use(['/users', '/admin'], userAuth());
223
229
 
224
230
  app.use(router.routes());
225
231
  ```
232
+
226
233
  <a name="module_egg-router--Router+prefix"></a>
227
234
 
228
235
  #### router.prefix(prefix) ⇒ <code>Router</code>
236
+
229
237
  Set the path prefix for a Router instance that was already initialized.
230
238
 
231
239
  **Kind**: instance method of <code>[Router](#exp_module_egg-router--Router)</code>
@@ -235,12 +243,15 @@ Set the path prefix for a Router instance that was already initialized.
235
243
  | prefix | <code>String</code> |
236
244
 
237
245
  **Example**
246
+
238
247
  ```javascript
239
248
  router.prefix('/things/:thing_id')
240
249
  ```
250
+
241
251
  <a name="module_egg-router--Router+allowedMethods"></a>
242
252
 
243
253
  #### router.allowedMethods([options]) ⇒ <code>function</code>
254
+
244
255
  Returns separate middleware for responding to `OPTIONS` requests with
245
256
  an `Allow` header containing the allowed methods, as well as responding
246
257
  with `405 Method Not Allowed` and `501 Not Implemented` as appropriate.
@@ -255,6 +266,7 @@ with `405 Method Not Allowed` and `501 Not Implemented` as appropriate.
255
266
  | [options.methodNotAllowed] | <code>function</code> | throw the returned value in place of the default MethodNotAllowed error |
256
267
 
257
268
  **Example**
269
+
258
270
  ```javascript
259
271
  var Koa = require('koa');
260
272
  var Router = require('egg-router');
@@ -283,9 +295,11 @@ app.use(router.allowedMethods({
283
295
  methodNotAllowed: () => new Boom.methodNotAllowed()
284
296
  }));
285
297
  ```
298
+
286
299
  <a name="module_egg-router--Router+redirect"></a>
287
300
 
288
301
  #### router.redirect(source, destination, [code]) ⇒ <code>Router</code>
302
+
289
303
  Redirect `source` to `destination` URL with optional 30x status `code`.
290
304
 
291
305
  Both `source` and `destination` can be route names.
@@ -314,6 +328,7 @@ router.all('/login', ctx => {
314
328
  <a name="module_egg-router--Router+route"></a>
315
329
 
316
330
  #### router.route(name) ⇒ <code>Layer</code> &#124; <code>false</code>
331
+
317
332
  Lookup route with given `name`.
318
333
 
319
334
  **Kind**: instance method of <code>[Router](#exp_module_egg-router--Router)</code>
@@ -325,6 +340,7 @@ Lookup route with given `name`.
325
340
  <a name="module_egg-router--Router+url"></a>
326
341
 
327
342
  #### router.url(name, params, [options]) ⇒ <code>String</code> &#124; <code>Error</code>
343
+
328
344
  Generate URL for route. Takes a route name and map of named `params`.
329
345
 
330
346
  **Kind**: instance method of <code>[Router](#exp_module_egg-router--Router)</code>
@@ -337,6 +353,7 @@ Generate URL for route. Takes a route name and map of named `params`.
337
353
  | [options.query] | <code>Object</code> &#124; <code>String</code> | query options |
338
354
 
339
355
  **Example**
356
+
340
357
  ```javascript
341
358
  router.get('user', '/users/:id', (ctx, next) => {
342
359
  // ...
@@ -359,9 +376,11 @@ router.url('user', { id: 3 }, { query: { limit: 1 } });
359
376
  router.url('user', { id: 3 }, { query: "limit=1" });
360
377
  // => "/users/3?limit=1"
361
378
  ```
379
+
362
380
  <a name="module_egg-router--Router+param"></a>
363
381
 
364
382
  #### router.param(param, middleware) ⇒ <code>Router</code>
383
+
365
384
  Run middleware for named route parameters. Useful for auto-loading or
366
385
  validation.
367
386
 
@@ -373,6 +392,7 @@ validation.
373
392
  | middleware | <code>function</code> |
374
393
 
375
394
  **Example**
395
+
376
396
  ```javascript
377
397
  router
378
398
  .param('user', (id, ctx, next) => {
@@ -391,9 +411,11 @@ router
391
411
  // /users/3 => {"id": 3, "name": "Alex"}
392
412
  // /users/3/friends => [{"id": 4, "name": "TJ"}]
393
413
  ```
414
+
394
415
  <a name="module_egg-router--Router.url"></a>
395
416
 
396
417
  #### Router.url(path, params [, options]) ⇒ <code>String</code>
418
+
397
419
  Generate URL from url pattern and given `params`.
398
420
 
399
421
  **Kind**: static method of <code>[Router](#exp_module_egg-router--Router)</code>
@@ -406,6 +428,7 @@ Generate URL from url pattern and given `params`.
406
428
  | [options.query] | <code>Object</code> &#124; <code>String</code> | query options |
407
429
 
408
430
  **Example**
431
+
409
432
  ```javascript
410
433
  var url = Router.url('/users/:id', {id: 1});
411
434
  // => "/users/1"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eggjs/router",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "engines": {
5
5
  "node": ">= 8.5.0"
6
6
  },
@@ -11,7 +11,7 @@
11
11
  "description": "Router middleware for egg/koa. Provides RESTful resource routing.",
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/eggjs/egg-router.git"
14
+ "url": "git@github.com:eggjs/router.git"
15
15
  },
16
16
  "bugs": {
17
17
  "url": "https://github.com/eggjs/egg/issues"