Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saadq/koa-combine-routers
Middleware for composing multiple instances of koa-router.
https://github.com/saadq/koa-combine-routers
Last synced: 26 days ago
JSON representation
Middleware for composing multiple instances of koa-router.
- Host: GitHub
- URL: https://github.com/saadq/koa-combine-routers
- Owner: saadq
- License: mit
- Created: 2016-09-02T23:22:23.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-10-02T07:41:45.000Z (about 6 years ago)
- Last Synced: 2024-08-04T00:03:59.714Z (4 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/koa-combine-routers
- Size: 47.9 KB
- Stars: 39
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-koa - koa-combine-routers - 组合多个[@koa/router](https://github.com/koajs/koa-router)实例。 ![](https://img.shields.io/github/stars/saadq/koa-combine-routers.svg?style=social&label=Star) ![](https://img.shields.io/npm/dm/koa-combine-routers.svg?style=flat-square) (仓库 / 中间件)
README
# koa-combine-routers
[![Build Status](https://travis-ci.org/saadq/koa-combine-routers.svg?branch=master)](https://travis-ci.org/saadq/koa-combine-routers)
Convenience middleware for composing multiple instances of [koa-router](https://github.com/alexmingoia/koa-router).
For usage with Koa 1.X, check out the [`old`](https://github.com/saadq/koa-combine-routers/tree/old) branch.
## Installation
```
$ npm install koa-combine-routers
```## Usage
**app.js**
```javascript
const Koa = require('koa')
const router = require('./routes')const app = new Koa()
app.use(router())
```**routes.js**
```javascript
const Router = require('koa-router')
const combineRouters = require('koa-combine-routers')const dogRouter = new Router()
const catRouter = new Router()dogRouter.get('/dogs', async ctx => {
ctx.body = 'ok'
})catRouter.get('/cats', async ctx => {
ctx.body = 'ok'
})const router = combineRouters(
dogRouter,
catRouter
)module.exports = router
```## API
| param | type | description |
| ------- | ------------------------- | ------------------------------------------------- |
| routers | `Object[]` \| `...Object` | An array of routers or multiple router arguments. |#### combineRouters(routers)
#### combineRouters(...routers)