重叠路线在 Koa.js 中不起作用

Overlapping routes are not working in Koa.js

当我调用 /my/abc/create 时,由于第一个入口点,我总是获得状态 400。 如何调用第二个端点?我不想更改入口点顺序。

var Router = require('koa-router');

var router = Router();


router.get('/my/:path/:id', (ctx) =>{
    if (isNaN(Number(cox.params.id))) { // if not numeric
        ctx.status = 400;
        return;
    }
    console.log('route id')
})
router.get('/my/:path/create', (ctx) =>{ 
    console.log('route create')
})

从 REST 的角度来说,您根本不会有 create 路由:

router.get('/my/:path/:id', (ctx) => /* get entity */)
router.post('/my/:path', (ctx) => /* create entity */)
router.patch('/my/:path/:id', (ctx) => /* update entity */)
router.delete('/my/:path/:id', (ctx) => /* delete entity */)