在node.jsexpression式中,对“/ locations / search”的请求总是进入“/ locations /:location_id”,如何以正确的方式进行路由

我使用node.js express来构build一个简单的web api,就像这样

app.get('/locations/:location_id',getLocationByID); -- first form app.get('/locations/search',searchLocation); -- second form 

但是,当URL以第二种forms“/ locations / search”结构化时,请求将始终转到第一种。 我怎么能智能地告诉快递从这两种不同forms的url分开?

首先进行/search。

 app.get('/locations/search',searchLocation); app.get('/locations/:location_id',getLocationByID); 

Express按照它们添加的顺序处理路由。