[英]How to edit, for example, the header of one HTML file and make it do the same to all other pages, without changing all the pages manually?
[英]How to route all express pages to a unique pages (Without html extension)
我的静态内容文件夹中有一堆页面
index.html
about.html
dashboard.html
如何将所有这些路由到他们的页面而不 having.url 中的 html。我想用一种方法做到这一点而不必像这样:
app.route('/about').get(function(req, res) {
return res.sendFile(path.join(__dirname, 'static-content/about.html'));
});
app.route('/dashboard').get(function(req, res) {
return res.sendFile(path.join(__dirname, 'static-content/dashboard.html'));
});
www.mysite.com/about
www.mysite.com/dashboard
那么,根据express.static
可用选项,您可以使用extensions: ['html']
在express.static
中。
app.use(express.static(__dirname + '/public', {
extensions: ['html']
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.