Router.match is returning pathAndMethod matches for layers without methods such as nested routers or middleware
See original GitHub issueDescription 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.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Router in axum::routing - Rust - Docs.rs
Nest a group of routes (or a Service ) at some path. This allows you to break your application into smaller pieces and...
Read more >Vert.x Web
Some of the key features of Vert.x-Web include: Routing (based on method, path, etc). Regular expression pattern matching for paths.
Read more >Migrating to React Router v6: A complete guide
Migrate your React Router applications from v5 to v6 with this in-depth guide ... For nested routes, developers had to find the entire...
Read more >Router middleware for koa. Provides RESTful resource routing.
function koa-router.layer (path, methods, middleware, opts) ... `Route#match` are now pure functions that return an array of routes that match the URL path....
Read more >The Guide to Nested Routes with React Router - ui.dev
The mental model I use for Route is that it always has to render something – either its element prop if the path...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I figured it out. First time contributing to open source. Learned a lot.
@jmealo I have already approved #106, just waiting on a core contributor to take a look and possibly merge.