ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、视频、阅读、搜索等,送10W Token,即刻开启你的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) ~~~