[英]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';
});
127.0.0.1:300/test
作品
127.0.0.1:300/1/test
不起作用
我看不到问题吗?
使用嵌套路由时,需要使用router.use
而不是router.get
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.