在Express中的所有路径中添加trailling斜杠

时间:2015-05-30 18:18:49

标签: node.js express

如何将/about重定向到/about/以及我在Express中的所有其他后续路线?我听说这是最好的做法。

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

1 个答案:

答案 0 :(得分:1)

您可以使用connect-slashes中间件 - https://www.npmjs.com/package/connect-slashes