2017-09-12 6 views
0

これは私が思っている疑似コードです。koaで条件付きでURLをリダイレクトする方法2

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
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 
    } 
} 
関連する問題