Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Express.js Routing wrong route

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?

like image 963
Simon Appelt Avatar asked Oct 29 '25 12:10

Simon Appelt


1 Answers

Routes in express.js are executed in order.

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

like image 159
Muhammad Usman Avatar answered Oct 31 '25 02:10

Muhammad Usman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!