4

I have 3 express.js routes

app.get('/packages/:name', (req, res) => {...});
app.get('/packages/search/', (req, res) => {...});
app.get('/packages/search/:name', (req, res) => {...});

The first and thrid routes are working just fine. But the second route is never triggert. When I browse to "localhost/packages/search/" it will trigger the first route with res.params.name = "search/"

I can do an "if" to check if its "search/" but i don't think thats a good solution.

Am I doing something wrong?

Simon Appelt
  • 305
  • 4
  • 12

1 Answers1

2

Routes in express.js are executed in order.

For detail Node.js Express route naming and ordering: how is precedence determined?

Community
  • 1
  • 1
Muhammad Usman
  • 345
  • 1
  • 11