Router Parameters - Merge Parameters


#1

project link: https://www.codecademy.com/programs/a69cb81af830c13c873cb401c07e39a0/content-items/729e5920fc7e4faba61716fc3b105307/exercises/merge-params

Part 3:

I believe there is a typo:
newSpice.spiceRackId equal to the req.params.spiceRackId should say instead:
newSpice.spiceRackId equal to the req.params.id

Or, I just don’t understand this section very well. It was kind of clunkily written and confusing…

If I understood correctly, this concept is similar to React’s inheritance structure. If that’s true, then taking the app.js info passed from the spiceRack object would requre us to reference the “id” parameter from the request if it’s getting passed into the spicesRouter.js correctly with the {mergedParams: true} setting determined in step 2.


#2

I was not able to get to the correct lesson from your link. I believe you are meaning: Learn Express: Middleware - Router Parameters

Quick answer to your question: No. The req.params.spiceRackId is referring to the spiceRackId on line 73 of app.js app.use('/spice-racks/:spiceRackId/spices', spicesRouter);. The name of the query parameter is spiceRackId, not id. Therefore, req.params.id in spicesRouter.js would return null.