rest - Node.js Express nested resources -


I want to do nest like the resources below.

  /// fileA .js app.use ('/ dashboards /: dashboard_id / teams', teams); [...] ///teams.js router.get ('/', function (Rick, race, next) {[...]}  

but I can not Receive the parameter req.params ["dashboard_id"] in teams , because it appears to have already been replaced with parameter value. I have a problem by passing an intermediate function and passing the parameter But I do not know that ... do you have any answer? Thanks, Franco

You can try this solution:

  // Announce a function that will pass the primary router's paramas for request var passPrimaryParam = function (req) , Res, next) {req.primaryParams = req.params; next ();} /// fileA.js app.use ('/ dashboards /: dashboard_id / teams', passPrimaryParam); app.use (' / dashboards / : Dashboard_id / teams', teams); ///teams.js Router.get ('/', function (Rick, Race, Next) {var dashboardId = req.primaryParams ['Dashboard_ID']; // should work now // Here you can use req.params - current r external parameter}  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -