1
我是ExpressJS的新手,所以我想设置一个简单的字符串值,我可以翻译。ExpressJS app.locals.title提供:发送后无法设置标题
所以我尝试了globalize-express并设置应用程序的标题是这样的:
app.use(function (req, res, next) {
console.log("App: " + req.Globalize.formatMessage('strings/title'));
res.locals.title = req.Globalize.formatMessage('strings/title');
next();
});
依次为:
app.use('/', index);
它看起来是正确的渲染,但控制台发布的错误:
Can't set headers after they are sent.
如何避免此错误?
的可能的复制[错误:无法设置头后,他们被发送到客户端(https://stackoverflow.com/questions/7042340/error-cant-set-在发送给客户端之后的头文件) –
正确,发现在我的'index.js'中,我应该调用'router.get('/',function(req,res)'。ie无需在'router.get()'中调用'next()' – jkbadsberg