Alvin
Alvin

Reputation: 8499

why get is always hitting the first route

I am using express.

I have 2 routes:

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

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

Every time I call GET http://localhost:3000/users/search?name=@ I hit the fist route instead of the second one?

What should I change?

Upvotes: 2

Views: 159

Answers (1)

Jason Livesay
Jason Livesay

Reputation: 6377

Because /:id matches anything include /search. It thinks the id is 'search'. Try putting the '/search' route first, or change it to /find/:id.

Upvotes: 5

Related Questions