rocketspacer rocketspacer - 5 months ago 61
Node.js Question

Get params of parent router

Assume that I have 2 routers nested together like so:

var appRouter = express.Router();
var childRouter = express.Router();

app.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
in sub-router handler ?


Create the child router with

express.Router({ mergeParams: true })