/koa-combine-routers

Middleware for composing multiple instances of koa-router.

Primary LanguageJavaScriptMIT LicenseMIT

koa-combine-routers

Build Status

Convenience middleware for composing multiple instances of koa-router.

For usage with Koa 1.X, check out the old branch.

Installation

$ npm install koa-combine-routers

Usage

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

API

param type description
routers Object[] | ...Object An array of routers or multiple router arguments.

combineRouters(routers)

combineRouters(...routers)