怎样用原生 Koa 实现路由功能

index.js

const Koa = require("koa");
const app = new Koa();

app.use((ctx) => {
  switch (ctx.url) {
    case "/":
      ctx.body = "<h1>index.html</h1>";
      break;
    default:
      ctx.body = "<h1>404 Not Found.</h1>";
  }
});

app.listen(3000);

原文地址:https://www.cnblogs.com/aisowe/p/15245787.html