Convenience middleware for composing multiple instances of koa-router.
For usage with Koa 1.X, check out the old
branch.
$ npm install koa-combine-routers
app.js
const Koa = require('koa')
const router = require('./routes')
const app = new Koa()
app.use(router())
routes.js
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
param | type | description |
---|---|---|
routers | Object[] | ...Object |
An array of routers or multiple router arguments. |