Karl Morrison Karl Morrison - 1 year ago 202
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download