Reputation: 10681
How can I redirect /about
to /about/
and all my other subsequent routes in Express? I heard that its best practice to do so.
app.js
// Enable strict routing
app.set('strict routing', true);
app.route('/').get(function(req, res) {
res.render('index', {
title: 'Welcome'
});
});
app.route('/about').get(function(req, res) {
res.render('about', {
title: 'About'
});
});
//etc
Upvotes: 2
Views: 73
Reputation: 301167
There is the connect-slashes
middleware that you can make use of - https://www.npmjs.com/package/connect-slashes
Upvotes: 1