企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持知识库和私有化部署方案 广告
~~~ const Koa = require("koa"); const app = new Koa(); let router = require("koa-router")(); //配置路由 router.get("/",async (ctx,next)=>{ ctx.body="首页" }).get('/news',async (ctx,next)=>{ ctx.body = "新闻"; //动态路由 }).get('/news/:id',async (ctx)=>{ //1.在地址后面配置aid //2.ctx.params获取动态路由的传值 console.log(ctx.params); //{ aid: '456' } ctx.body="新闻详情"; }) app.use(router.routes()).use(router.allowedMethods()); app.listen(3400) ~~~