express 怎么对以下代码进行简写

//登录
app.get(`/business-login`,function(req,res){
if(!app.locals.isLogin){
res.redirect('/')
}
res.render(`business-login.html`);
});
//申请入驻
app.get(`/business-apply`,function(req,res){
if(!app.locals.isLogin){
res.redirect('/')
}
res.render(`business-apply.html`);
});
//审核中
app.get(`/business-review`,function(req,res){
if(!app.locals.isLogin){
res.redirect('/')
}
res.render(`business-review.html`);
});
上面写了三个在判断是否登录的,如何进行简写啊?
HUWWW
浏览 468回答 2
2回答

噜噜哒

functionisLogin(req,res,next){if(!app.locals.isLogin){res.redirect('/')}else{next()}}//登录app.get(`/business-login`,isLogin,function(req,res){res.render(`business-login.html`);});//申请入驻app.get(`/business-apply`,isLogin,function(req,res){res.render(`business-apply.html`);});//审核中app.get(`/business-review`,isLogin,function(req,res){res.render(`business-review.html`);});

慕桂英546537

app.get('/business-(login|apply|review)',function(req,res){if(!app.locals.isLogin){res.redirect('/')}res.render(req.originalUrl.substring(1)+'.html');});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript