Karl Morrison Karl Morrison - 4 months ago 56
Node.js Question

Koa-router not nesting

const router2 = new KoaRouter();
router2.get(`/test`, async function(ctx, next) {
ctx.body = 'api test';

const router = new KoaRouter();
router.get(`/1`, router2.routes(), router2.allowedMethods());
router.get(`/test`, async function(ctx, next) {
ctx.body = 'test';
does not work

I can't see the problem?


When you are using nested routes you need to use router.use instead of router.get.