簡體   English   中英

Koa路由器不嵌套

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM