这就是我在想的伪代码。
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);
}
};
Run Code Online (Sandbox Code Playgroud)
如何对其进行修改以使其正常工作?
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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5582 次 |
| 最近记录: |