-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using two routers, the next bug of regular routing #139
Comments
Normal if regular routing is not used routerA.get('/test/child', async (ctx,next) => {
console.log('/test/(.*?)');
await next()
}) |
对于/test/child,两个路由都匹配上了,然后依次执行了对应的handler,就产生了错误。 |
6 tasks
The same thing: const Koa = require('koa');
const Router = require('@koa/router');
const app = new Koa();
const router1 = new Router();
const router2 = new Router();
router1.get('/:id', async (ctx, next) => {
console.log('1 >>', ctx.params.id);
await next();
});
router2.get('/:id', async (ctx, next) => {
console.log('2 >>', ctx.params);
ctx.body = ctx.params;
});
app
.use(router1.routes())
.use(router2.routes());
app.listen(3002);
console.log('KOA is on 3002'); on
created pr for this issue: #160 |
@1stgg it can be solved by redefined let app = new (require("koa"))()
let routerA = new (require("koa-router"))()
let routerB = new (require("koa-router"))()
routerA.get('/test/(.*?)', async (ctx,next) => {
console.log('/test/(.*?)');
ctx.routerPath = `/test/${ctx.params[0]}`;
await next()
})
routerB.get('/test/child', async (ctx) => {
ctx.body = '/test/child';
})
app.use(routerA.routes())
app.use(routerB.routes())
app.listen(3000, () => {
console.log('应用已经启动,http://localhost:3000');
}) |
Fixed through this PR (#160) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
node.js version: v14.17.6
npm/yarn and version: 1.22.11
@koa/router
version: 10.1.1koa
version: 2.13.4Code sample:
Expected Behavior:
GET http://localhost:3000/test/child
response.body = '/test/child'
Actual Behavior:
GET http://localhost:3000/test/child
response 404 Not Found
Additional steps, HTTP request details, or to reproduce the behavior or a test case:
The text was updated successfully, but these errors were encountered: