假设我有两个嵌套在一起的路由器:
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 ?
});
有没有办法在子路由器处理程序中获取parentId
?
答案 0 :(得分:6)
使用
创建子路由器express.Router({ mergeParams: true })