So imagine if the current file I'm in is an express.Router() for the endpoint /post.
I tried to require a different router within the /post router called /:id (which is a url param), sorta like this: router.use("/:id", require("./idRouter"));. So, if I go to idRouter.js (which' route is /post/:id) and write something like this:
router.get("/like", (req, res) => {
console.log(req.params.id)
res.send({status:"SUCCESS"});
});
And then if I go to the endpoint in a browser (for example /post/12345/like) it does respond with {"status":"SUCCESS"} but req.params.id is undefined, so I can't use it. Is this a bug or is this deliberate (for some reason)?
Note: req.params is an empty object
So imagine if the current file I'm in is an express.Router() for the endpoint /post.
I tried to require a different router within the /post router called /:id (which is a url param), sorta like this:
router.use("/:id", require("./idRouter"));. So, if I go to idRouter.js (which' route is /post/:id) and write something like this:And then if I go to the endpoint in a browser (for example /post/12345/like) it does respond with {"status":"SUCCESS"} but
req.params.idis undefined, so I can't use it. Is this a bug or is this deliberate (for some reason)?Note:
req.paramsis an empty object