无法从主页路由我的页面以显示路由

时间:2019-04-03 05:21:59

标签: node.js express

//这不起作用,请帮助 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});
    }
});

});

1 个答案:

答案 0 :(得分:0)

尽管您尚未定义代码发生了什么错误。请再次检查您的路由器,可以使用此代码段作为最佳做法,谢谢您

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