Why does req.params return an empty array?

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 });

req.params
can only get the param of request url in this pattern:/user/:name

req.query
get query params(name) like /user?name=123 or body params.


req.params only contain the route params, not query string params (from GET) and not body params (from POST). The param() function however checks all three, see:

http://expressjs.com/4x/api.html#req.params