0

i have an express routing file where i define all my routes . The problem is when i have tow routes with similar urls for example :

router.get('/:categoryId/', getProductsByCategory)
router.get('/:productId', getProduct)

and try to test with postman it always exacute the first route in order no matter which route i test so if the route with categoryId is above in the file it will execute getProductsByCategory even if i put the other url with productId and vide versa . I searched on internet but didn't find this issue anywhere. Thank you for your help !

Ghost
  • 318
  • 2
  • 8
  • Does this answer your question? [Order of router precedence in express.js](https://stackoverflow.com/questions/32603818/order-of-router-precedence-in-express-js) – Phil Mar 01 '22 at 02:41

1 Answers1

0

@ghost Express routing follow up to down flow we can not define same routes name here you set same routes have to give different address try below routes and also follow this routes via postman

router.get('/category/:categoryId/', getProductsByCategory)
router.get('/product/:productId', getProduct)

Hope you get this point just let me know there were any other issue with express routing

Smit Gajera
  • 1,001
  • 1
  • 8
  • 26