Param missing in app.use express route with nodejs Param missing in app.use express route with nodejs express express

Param missing in app.use express route with nodejs


I don't believe you can use the express router like that. The booking Routes router does not have access to the other routers param's because booking Routes only has access to anything after the 'parent' routers URL.

If you really feel the need to do it like that here is a little sample code to get around it. But id say try and restructure your API routes cause i'm not sure how good this is to do.

Sorry for so many edits. Decided it would be better to extract that logic into a middleware function

const bindHid = (req, res, next) => {  req.hid = req.params.hid;  next();}app.use('/homes/:hid/bookings', bindHid, bookingRoutes)bookingRoutes.use('/', (req, res, next) => {  res.send(req.hid)})