【发布时间】:2016-06-08 20:29:42
【问题描述】:
我有一个 Express / Angular 应用程序,我正在尝试通过 app.get() 方法添加标题,而不是通过 angular 添加标题。有没有办法在不使用模板引擎的情况下做到这一点?
我的 server.js 文件:
app.use(express.static(path.join(__dirname, 'public')));
我的路线(使用 express.Router)
// Default load public index.html
publicRouter.get('*', function(req, res) {
res.sendFile(path.join(__dirname, '../../../public', 'index.html'));
});
我很确定我做错了。我想做这样的事情:
publicRouter.get('*', function(req, res) {
res.sendFile(path.join(__dirname, '../../../public', 'index.html'), {
title: "My Webpage",
});
});
然后在我的 index.html 中,我可以将标题直接渲染到模板中:
<title>{{ title }}</title>
... 不属于路由范围的一部分。这是因为标题是在加载 Angular 之前呈现的,如果我在 Angular 中加载它,标签会在加载 Angular 时暂时显示。这不酷。
【问题讨论】:
标签: javascript angularjs node.js templates express