简体   繁体   中英

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:

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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