如何处理express.js路由?

我有类似的路线

app.get('/home',requireLogin,routes.home) exports.home = function(req, res){ res.render('index', { title: 'home' }); }; 

现在如果我想我的url看起来像这样

 /home/menu/someting 

我必须创build像这样的路线

 app.get('/home/menu/someting',requireLogin,routes.newRoutes) 

或者我可以只修改routes.home来处理其余的url,就像是有第二个/东西做某事。

我知道我可以有家/:参数,但我需要的url看起来完全像家/菜单/东西,后我会有:参数。

只是回答我这是可能的处理/ home和/ home /菜单在相同的路线,没有参数

您可以在路由中使用通配符( * )和命名参数( :parameter )。

 app.get('/home/menu/:something', ...) 

然后使用req.params.something作为值。

http://expressjs.com/api.html