rocketspacer rocketspacer - 1 year ago 117
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 ?

Answer Source

Create the child router with

express.Router({ mergeParams: true })
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download