Git Product home page Git Product logo

Comments (6)

jiladahe1997 avatar jiladahe1997 commented on June 2, 2024

I have found something that may help.

node_modules\koa-router\lib\router.js

 335 var mostSpecificLayer = matchedLayers[matchedLayers.length - 1];
 336 ctx._matchedRoute = mostSpecificLayer.path;

As shown in the code, ctx._matcheRoute is the most matched route path insteadof requested.

from koa-router.

schwarmco avatar schwarmco commented on June 2, 2024

I ran into the same problem. The issue is, that matchedLayers contains - as the name suggests - all matched layers, that will be put in the middleware-chain (because the regex matches).

In the case above, it's because :orderId could also be list. So, if the orderId-Middleware decides, it doesn't want to handle the request, it can call next() and the list-route will be called. That way the "mostSpecificLayer" isn't necessarily the "last" or "current" one.

With that being said, the ctx._matchedRoute is probably a bug - or at least misleadingly named.

I've created PR #524, which would populate ctx.routerPath

from koa-router.

tuananh avatar tuananh commented on June 2, 2024

@schwarmco this is the official one from koa org https://github.com/koajs/router , a fork of this repo

from koa-router.

schwarmco avatar schwarmco commented on June 2, 2024

@tuananh thanks - i opened a pull-request there... just landed here, because i searched for this exact same issue :)

from koa-router.

BainDragneel avatar BainDragneel commented on June 2, 2024

Thanks very much, I have some things I did not pay attention to this issue in time, sorry!

from koa-router.

BainDragneel avatar BainDragneel commented on June 2, 2024

Already got help:https://github.com/koajs/router/releases/tag/v9.1.0 Thx!!!!!

from koa-router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.