express的路由有没方法是同一个参数不用每个路由都写
app.get(’/’, function (req, res) { res.render(‘index’, { title: ‘首页’ , user: req.session.user }); });
app.get('/goods', function (req, res) {
res.render('goods', {
title: '商品列表'
** , user: req.session.user**
});
});
3 回复
写到locals上
app.use(function(req, res, next){
res.locals.user = req.session.user;
next();
});
@magicdawn 好的,thx