koa-route模块

2018-04-12 14:29:03 浏览数 (1)

代码语言:javascript复制
const Koa = require('koa');
const route = require('koa-route');
const app = new Koa();

const about = ctx => {
    ctx.response.body = 'Hello World111';
};

const main = ctx => {
    ctx.response.body = 'Hello World222';
};
const details = (ctx,id) => {
    ctx.response.body = id 'Hello World222';
};

app.use(route.get('/', main));
app.use(route.get('/about', about));
app.use(route.get('/details/:id', details)); //参数一定要写在斜杠冒号后面

// app.use(main);
app.listen(3000);

0 人点赞