Why does req.params return an empty array?

后端 未结 3 1071
野的像风
野的像风 2021-02-01 06:10

I\'m using Node.js and I want to see all of the parameters that have been posted to my script. To get to my function, in my routes/index.js I\'m doing:



        
3条回答
  •  心在旅途
    2021-02-01 06:53

    I had a similar problem and thought I'd post the solution to that for those coming here for the same reason. My req.params was coming out as an empty object because I declared the URL variable in the parent route. The solution is to add this option to the router:

    const router = express.Router({ mergeParams: true });
    

提交回复
热议问题