im making posts, comment etc i want to redirect upper route. im making delete post's comment.
after delete, i want to redirect upper route, without a specific route
router.route('/post/comment/destroy/:postroot').post(function (req, res) {
var database = req.app.get('database')
var postroot = path.parse(req.params.postroot).base;
var filterd = req.body.commentid;
database.PostModel.findOne({
"_id": postroot
}, function (err, rawContent) {
if (err) throw err;
var idx;
for (var i = 0; i < rawContent.comments.length ; i++){
if (rawContent.comments[i]._id == filterd) {
idx = i;
break;
}
}
rawContent.comment.commentcount-=1;
rawContent.comments.splice(idx, 1);
rawContent.save(function (err) {
if (err) throw err;
});
});
res.redirect(`/post/${postroot}`);
});
simply use your params inside the router
res.redirect('/post/'+req.params.postroot);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.