Open
Description
Description
When using nested routers and other middleware, the Router.match can include layers without methods in the matched.pathAndMethod array. This can cause issues downstream when setting the ctx._matchedRouteName, causing named routes to not be set properly. The assumption being that the last item in the pathAndMethod array being the most specific layer.
node.js version: v12.18.3
npm/yarn and version: 6.14.6
@koa/router
version: 9.4.0
koa
version: 2.13.0
Code sample:
const Koa = require('koa')
const Router = require('@koa/router')
const app = new Koa()
const router = new Router()
router.get('main#info', '/info', function() {})
const nestedRouter = new Router()
nestedRouter.get('nested#name', '/updates', function() {})
router.use('/v1/api', nestedRouter.routes(), nestedRouter.allowedMethods())
app.use(router.routes()).use(router.allowedMethods())
app.listen(8084)
Expected Behavior:
Only layers with path and methods should be included in matched.pathAndMethods array.
Actual Behavior:
Any layer which matches the given path will appear in matched.pathAndMethods array. Even if the layer has zero methods associated with them.
Metadata
Assignees
Labels
No labels