diff --git a/API.md b/API.md index e8394db..086f7a2 100644 --- a/API.md +++ b/API.md @@ -1,21 +1,24 @@ ## API Reference -* [koa-router](#module_koa-router) - * [Router](#exp_module_koa-router--Router) ⏏ - * [new Router([opts])](#new_module_koa-router--Router_new) - * _instance_ - * [.get|put|post|patch|delete|del](#module_koa-router--Router+get|put|post|patch|delete|del) ⇒ Router - * [.routes](#module_koa-router--Router+routes) ⇒ function - * [.use([path], middleware)](#module_koa-router--Router+use) ⇒ Router - * [.prefix(prefix)](#module_koa-router--Router+prefix) ⇒ Router - * [.allowedMethods([options])](#module_koa-router--Router+allowedMethods) ⇒ function - * [.redirect(source, destination, [code])](#module_koa-router--Router+redirect) ⇒ Router - * [.route(name)](#module_koa-router--Router+route) ⇒ Layer | false - * [.url(name, params, [options])](#module_koa-router--Router+url) ⇒ String | Error - * [.param(param, middleware)](#module_koa-router--Router+param) ⇒ Router - * _static_ - * [.url(path, params)](#module_koa-router--Router.url) ⇒ String +- [API Reference](#api-reference) + - [Router ⏏](#router-) + - [new Router([opts])](#new-routeropts) + - [router.get|put|post|patch|delete|del ⇒ Router](#routergetputpostpatchdeletedel--router) + - [Named routes](#named-routes) + - [Multiple middleware](#multiple-middleware) + - [Nested routers](#nested-routers) + - [Router prefixes](#router-prefixes) + - [URL parameters](#url-parameters) + - [router.routes ⇒ function](#routerroutes--function) + - [router.use([path], middleware) ⇒ Router](#routerusepath-middleware--router) + - [router.prefix(prefix) ⇒ Router](#routerprefixprefix--router) + - [router.allowedMethods([options]) ⇒ function](#routerallowedmethodsoptions--function) + - [router.redirect(source, destination, [code]) ⇒ Router](#routerredirectsource-destination-code--router) + - [router.route(name) ⇒ Layer | false](#routerroutename--layer--false) + - [router.url(name, params, [options]) ⇒ String | Error](#routerurlname-params-options--string--error) + - [router.param(param, middleware) ⇒ Router](#routerparamparam-middleware--router) + - [Router.url(path, params) ⇒ String](#routerurlpath-params--string) @@ -224,8 +227,20 @@ Set the path prefix for a Router instance that was already initialized. **Example** ```javascript -router.prefix('/things/:thing_id') +const router = new Router({ + prefix: '/categories' +}); + +router.get('/', ...); // respond "/categories" + +router.prefix('/users'); + +router.get('/', ...); // responds to "/users" +router.get('/:id', ...); // responds to "/users/:id" ``` + +**Note**: prefix always should start from `/` otherwise it won't work. + #### router.allowedMethods([options]) ⇒ function