这就是我所想的伪代码。
const myRedirect = (routePath) => {
newUrl = routePath;
if (matches condition)
newUrl = do_some_modification(routePath);
return next(newUrl);
}
const myFunc = (routePath, myRedirect) => (newUrl, middleware) => {
return (ctx, newUrl, next) => {
return middleware(ctx, newUrl, next);
}
};
如何对其进行修改以使其正常工作?
答案 0 :(得分:1)
const route = async function(ctx, next){
if(shouldRedirect){
ctx.redirect('/redirect-url') // redirect to another page
}
else{
ctx.someData = getSomeData() // ctx.someData will be available in the next middleware
await next() // go to next middleware
}
}