Answer the question
In order to leave comments, you need to log in
How to properly set up a route in a NodeJS+express+mongoose app?
Route set up:
router.route('/:category/:id')
.get(defaultController.singlePost);
singlePost:async (req, res) => {
const id = req.params.id;
const categories = await Category.find().lean();
const categoryTitleId = Category.findOne({category:req.params.category});
console.log(req.params.category);
console.log(categoryTitleId);
/***/
Post.findById(id).lean()
.then(post => {
res.status(200);
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.render('default/singlePost', {post: post, categories: categories});
})
.catch(function(err) {
//res.status(404).json({message: 'No post found'});
res.status(404);
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.render('404.handlebars', { url: req.url });
return;
//return res.json(err);
});
/***/
}
<a href="/{{category}}/{{_id}}" class="btn btn-primary">Read More →</a>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question