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';
});
127.0.0.1:300/test
works
127.0.0.1:300/1/test
does not work
I can't see the problem?
使用嵌套路由时,需要使用router.use
而不是router.get
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.