为什么下面的代码输出为'one',而不是'one''2'?但使用快速路线是好的
app.use(route.get('/admin',requiredUser,index));
function *requiredUser(next){
console.log("one"); //required session
yield next;
}
function *index(next) {
console.log("two"); //ok save login
this.body = yield render('admin');
}
1 回答
koa-route只需要一个处理程序 - 无论你给它的第二个参数 . 这就是为什么它只执行你的第一个处理程序 .
您可以使用https://github.com/koajs/compose将一组处理程序合并为一个:
或者您可以使用另一个路由库,如https://github.com/alexmingoia/koa-router,它具有您最初期望从koa-route行为: