【问题标题】:Cannot route my page from main page to show route无法从主页路由我的页面以显示路由
【发布时间】:2019-04-03 15:20:46
【问题描述】:

//这不起作用请帮助 app.get("/dishes/:id", function(req, res){

dishes.findById(req.params.id, function(err, founddishes){
    if(err){
        console.log(err);
    } else {
        // Render show template with that campground
        res.render("show", {dishes: founddishes});
    }
});

});

【问题讨论】:

  • “不工作”是什么意思?你有错误吗?您是否还检查了 req.params.id 是否已填充?
  • 能否请您发布一个完整的小例子,它也有同样的问题。帮助会更容易

标签: node.js express


【解决方案1】:

虽然你没有定义你的代码发生了什么错误。请再次检查您的路由器,您可以使用此片段进行最佳实践,谢谢

dishes.findById(req.params.id)
.then((founddishes) => {
  if(founddishes){
    res.render("show", {dishes: founddishes});
  } else {
    throw[{msg: "Not found"}]
  }
})
.catch((errors) => {
  console.log(errors);
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    • 1970-01-01
    • 2018-01-21
    • 2017-08-14
    相关资源
    最近更新 更多