简体   繁体   English

如何将所有快递页面路由到一个独特的页面(没有 html 扩展名)

[英]How to route all express pages to a unique pages (Without html extension)

I have a bunch of pages in my static-content folder我的静态内容文件夹中有一堆页面

index.html
about.html
dashboard.html

How do route all of these to their page without having.html in the url. I want to this in one method without having to do it like this:如何将所有这些路由到他们的页面而不 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

Well, according to express.static available options, you can make this work with using extensions: ['html'] within the express.static .那么,根据express.static可用选项,您可以使用extensions: ['html']express.static中。

app.use(express.static(__dirname + '/public', {
  extensions: ['html']
}));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM