Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The ctx. _matchedRoute is not the match route.

See original GitHub issue

node.js version: v13.0.1

npm/yarn and version: 6.12.0

koa-router version: 7.4.0 and i tried @koa/router v8.0.2, too.

koa version: 2.7.0

Code sample:

Now I have two routes, one is “/api/order/list” and another is “/api/order/:orderId” ,

const Router = require("koa-router");
const router = new Router({
    "prefix": "/api",

I want to log each request.I want the url I am recording to be the url of my own defined api, not the url directly with params.For example, when I request “”, I want to record that the url is “/api/order/:orderId” instead of “/api/order/57d52c52403f2ee865738ec7”,And when I request “”, I want to record that the url is “/api/order/list” instead of “/api/order/:orderId”. But ctx. _matchedRoute is not the route I requested.

Expected Behavior:

when I request “”, ctx. _matchedRoute is “/api/order/:orderId”

Actual Behavior:

ctx. _matchedRoute is “/api/order/list”

Additional steps, HTTP request details, or to reproduce the behavior or a test case:

i have the four screenshots.


image ctx.matched image


image ctx.matched image

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

niftylettucecommented, Jun 30, 2020

@koa/router v9.1.0 released to npm and mirrored to koa-router as well

mdenisovcommented, Jun 30, 2020

@niftylettuce I transferred this PR from the original repo and this fix solves this problem. Works great on my project 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - Koa-router getting parsed params before hitting route
It seems to me that you need ctx.path , not ctx.originalUrl , as the original url contains the querystring, which will cause the...
Read more >
middleware - Go Packages
If two offers match with equal weight and specificity, then the offer earlier in the list is preferred. If no offers match, then...
Read more >
Routing - Fiber
This route path will match requests to the root route, "/": ... after the routes that contain fixed parts, so that these variable...
Read more >
Match - React Router: Declarative Routing for React.js
If a Route does not have a path , and therefore always matches, you'll get the closest parent match. Same goes for withRouter...
Read more >
Documentation - A lightweight Java and Kotlin web framework
Endpoint-handlers are matched in the order they are defined. You might know endpoint-handlers as routes or middleware from other libraries. Java; Kotlin. app....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found