ZijianHe / koa-router

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

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

Open cevio opened 5 years ago

cevio commented 5 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';

if

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

Also got 404. I fixed it. Thanks!