为什么得到总是击中第一条路线

时间:2016-09-28 03:54:38

标签: node.js express

我正在使用快递。

我有两条路线:

router.get('/:id', function (req, res, next) {

router.get('/search', function (req, res, next) {

每次我打电话给GET http://localhost:3000/users/search?name=@我都会打第一条路线而不是第二条路线?

我应该改变什么?

1 个答案:

答案 0 :(得分:4)

因为/:id匹配包含/search的任何内容。它认为id是搜索'。 尝试将' / search'首先路由,或将其更改为/find/:id