//登录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`);});上面写了三个在判断是否登录的,如何进行简写啊?
2 回答
噜噜哒
TA贡献1784条经验 获得超7个赞
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
TA贡献1848条经验 获得超10个赞
app.get('/business-(login|apply|review)',function(req,res){if(!app.locals.isLogin){res.redirect('/')}res.render(req.originalUrl.substring(1)+'.html');});
添加回答
举报
0/150
提交
取消