[英]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.