当我访问这条路线时,它没有在 url 中提供用户 ID

It is not giving userid in url when i visit this route

router.get("/dashboard/profile/:userid", auth, async (req, res) => {
  try {
      const userid = req.params.user.id;
    // request.user is getting fetched from Middleware after token authentication
      const user = await User.findById(userid);
      res.json(user);
  } catch (e) {
    res.send({ message: "Error in Fetching user" });
  }
});

module.exports = router

这是我的获取路径,我试图从用户那里获取 params.id 但它不起作用

替换这个

const userid = req.params.user.id 

const userid = req.params.userid

userid 是一个键。但是你用 user.id 分开了。所以使用

const userid = req.params.userid;

而不是

const userid = req.params.user.id;

its not working only getting localhost:3000/dashboard/profile ?

您的路径中缺少 userid 值。

请检查是否有三段。

dashboard/profile/:userid
 1         2         3

但是你的路径是(问题)

localhost:3000/dashboard/profile
                 1         2

请不要考虑主机名和端口。在/

之后计算

解决方案

localhost:3000/dashboard/profile/YourUserID
                1         2        3(//add your userid here)