5
我正在使用koa-router。Koa路由器:如何獲取查詢字符串參數?
我怎樣才能得到請求的查詢字符串參數?
這是我好不容易纔寫的最好的:
import koaRouter from 'koa-router';
const router = koaRouter({ prefix: '/courses' });
router.get('/', async (ctx) => {
console.log(ctx.qs["lecturer"]);
});
但qs
未定義
任何幫助將深刻地感謝!
ctx.request.query未定義,雖然ctx.request.url是'/ api/courses?lecturer = John_Smith' – Alon
@Alon你如何將路由器安裝到應用程序上? – robertklep
我不知道發生了什麼變化,但突然ctx.request.query正在工作 – Alon