|
1 | 1 |
|
2 | 2 | ## API Reference
|
3 | 3 |
|
4 |
| -* [koa-router](#module_koa-router) |
5 |
| - * [Router](#exp_module_koa-router--Router) ⏏ |
6 |
| - * [new Router([opts])](#new_module_koa-router--Router_new) |
7 |
| - * _instance_ |
8 |
| - * [.get|put|post|patch|delete|del](#module_koa-router--Router+get|put|post|patch|delete|del) ⇒ <code>Router</code> |
9 |
| - * [.routes](#module_koa-router--Router+routes) ⇒ <code>function</code> |
10 |
| - * [.use([path], middleware)](#module_koa-router--Router+use) ⇒ <code>Router</code> |
11 |
| - * [.prefix(prefix)](#module_koa-router--Router+prefix) ⇒ <code>Router</code> |
12 |
| - * [.allowedMethods([options])](#module_koa-router--Router+allowedMethods) ⇒ <code>function</code> |
13 |
| - * [.redirect(source, destination, [code])](#module_koa-router--Router+redirect) ⇒ <code>Router</code> |
14 |
| - * [.route(name)](#module_koa-router--Router+route) ⇒ <code>Layer</code> | <code>false</code> |
15 |
| - * [.url(name, params, [options])](#module_koa-router--Router+url) ⇒ <code>String</code> | <code>Error</code> |
16 |
| - * [.param(param, middleware)](#module_koa-router--Router+param) ⇒ <code>Router</code> |
17 |
| - * _static_ |
18 |
| - * [.url(path, params)](#module_koa-router--Router.url) ⇒ <code>String</code> |
| 4 | +- [API Reference](#api-reference) |
| 5 | + - [Router ⏏](#router-) |
| 6 | + - [new Router([opts])](#new-routeropts) |
| 7 | + - [router.get|put|post|patch|delete|del ⇒ <code>Router</code>](#routergetputpostpatchdeletedel--router) |
| 8 | + - [Named routes](#named-routes) |
| 9 | + - [Multiple middleware](#multiple-middleware) |
| 10 | + - [Nested routers](#nested-routers) |
| 11 | + - [Router prefixes](#router-prefixes) |
| 12 | + - [URL parameters](#url-parameters) |
| 13 | + - [router.routes ⇒ <code>function</code>](#routerroutes--function) |
| 14 | + - [router.use([path], middleware) ⇒ <code>Router</code>](#routerusepath-middleware--router) |
| 15 | + - [router.prefix(prefix) ⇒ <code>Router</code>](#routerprefixprefix--router) |
| 16 | + - [router.allowedMethods([options]) ⇒ <code>function</code>](#routerallowedmethodsoptions--function) |
| 17 | + - [router.redirect(source, destination, [code]) ⇒ <code>Router</code>](#routerredirectsource-destination-code--router) |
| 18 | + - [router.route(name) ⇒ <code>Layer</code> | <code>false</code>](#routerroutename--layer--false) |
| 19 | + - [router.url(name, params, [options]) ⇒ <code>String</code> | <code>Error</code>](#routerurlname-params-options--string--error) |
| 20 | + - [router.param(param, middleware) ⇒ <code>Router</code>](#routerparamparam-middleware--router) |
| 21 | + - [Router.url(path, params) ⇒ <code>String</code>](#routerurlpath-params--string) |
19 | 22 |
|
20 | 23 | <a name="exp_module_koa-router--Router"></a>
|
21 | 24 |
|
@@ -224,8 +227,20 @@ Set the path prefix for a Router instance that was already initialized.
|
224 | 227 |
|
225 | 228 | **Example**
|
226 | 229 | ```javascript
|
227 |
| -router.prefix('/things/:thing_id') |
| 230 | +const router = new Router({ |
| 231 | + prefix: '/categories' |
| 232 | +}); |
| 233 | + |
| 234 | +router.get('/', ...); // respond "/categories" |
| 235 | + |
| 236 | +router.prefix('/users'); |
| 237 | + |
| 238 | +router.get('/', ...); // responds to "/users" |
| 239 | +router.get('/:id', ...); // responds to "/users/:id" |
228 | 240 | ```
|
| 241 | + |
| 242 | +**Note**: prefix always should start from `/` otherwise it won't work. |
| 243 | + |
229 | 244 | <a name="module_koa-router--Router+allowedMethods"></a>
|
230 | 245 |
|
231 | 246 | #### router.allowedMethods([options]) ⇒ <code>function</code>
|
|
0 commit comments