Assume that I have 2 routers nested together like so:
var appRouter = express.Router();
var childRouter = express.Router();
appRouter.use('/:parentId/childpath', childRouter);
childRouter.get('/:childId', (req, res, next) => {
console.log(req.params); //only childId
// How do I get parentId ?
});
Is there any way to get parentId
in sub-router handler ?
Create the child router with
express.Router({ mergeParams: true })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With