如何在Express中将/about
重定向到/about/
以及所有其他后续路由?我听说这样做是最佳做法。
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
最佳答案
您可以使用connect-slashes
中间件-https://www.npmjs.com/package/connect-slashes
关于node.js - 将尾斜杠添加到Express中的所有路由,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30549728/