1. 将路由拆分到另一个文件夹,并将其通过module暴露出去
    2. const router = require("koa-router")()
    3. router.get("/",(ctx)=>{
    4. ctx.body = "hello world"
    5. })
    6. router.get("/my",async ctx=>{
    7. ctx.body = "my"
    8. })
    9. router.get("/friend", async ctx=>{
    10. ctx.body = 'f'
    11. })
    12. module.exports = router
    1. 在主页面接收router
    2. const koa = require("koa")
    3. const router = require('./routers')
    4. const app = new koa()
    5. app.use(router.routes())
    6. app.listen(4000,()=>{
    7. console.log('服务器开启了');
    8. })