Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我想在 koa-router 中匹配 '/index?id=xxx' 之类的 url 时,如何获取 'id'?网络上大多数文章通常使用 url lick '/index/:id',但后端接口并非如此。
它在后端 API 上的工作方式相同,当您向 Web 服务器发出 GET 请求时,它会解析查询字符串并使用这些值来为您提供预期的响应。
使用 koa-router 处理 GET 请求时,您可以指定查询字符串,例如 '/index/:id',并使用代码中的值,您只需执行
var id = ctx.request.query.id;