ZijianHe / koa-router

Router middleware for koa.
MIT License
4.85k stars 407 forks source link

Fix the merge relationship between `prefix` and `path` #485

Closed cevio closed 6 years ago

cevio commented 6 years ago

Fix the merge relationship between prefix and path, so that path-to-regexp can correctly parse the regular expression.

I found the bug:

const Koa = require('koa');
const Router = require('koa-router');

const app = new Koa();
const router = new Router();

const test = new Router();

test.get('/test', async (ctx, next) => {
  ctx.body = 'hello world';
});

router.use('/abc', test.routes(), test.allowedMethods());

app.use(router.routes());
app.use(router.allowedMethods());

app.listen(9000);

When i view '/abc/test' , the result is '404';

I fixed it.

Thanks!