2017-09-12 1 views
0

Das ist, was ich denke, Pseudocode.Wie einige URL in der koa 2 bedingt umgeleitet werden

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); 
    } 
}; 

Wie kann ich es ändern, damit es funktioniert?

Antwort

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 
    } 
} 
Verwandte Themen