对于以下代码:
router.use('/campaigns/:campaign_uid', cache.node_cache, api_dynamic_campaign.router);
我有一个到另一个路由器的路由器路由,如下所示:
router.get('/data.json', campaigns);
处理程序如下所示:
function campaigns(request, response){
var campaign = api.get_campaign_from_request(request) || request.params.campaign_uid;
api.route_handler(request, response, {"campaign":campaign});
}
我的问题是处理程序无法访问request.params中的campaign_uid。 如何访问/传递campaign_uid到处理程序?
答案 0 :(得分:1)
router.get('/data.json', campaigns).Router({ mergeParams: true })
https://cedric.tech/blog/expressjs-accessing-req-params-from-child-routers