1.配置路由 app.js
// 引入模块 const Koa = require('koa'); const router = require('koa-router')(); /*引入是实例化路由 推荐*/ // 实例化 let app = new Koa(); router.get('/', async (ctx) => { ctx.body = '首页'; }) router.get('/news', async (ctx) => { ctx.body = '新闻列表页面'; }) router.get('/newscontent', async (ctx) => { ctx.body = '新闻详情'; }) app.use(router.routes()); app.use(router.allowedMethods()); app.listen(3000);
.