Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
How can I use params to dynamically create links

I am wondering if anyone has any suggestion on how to get around this error i am getting. I am using params to dynamically create links, however when i post a new blog post i am getting a casting error since it tries to create a new link before the blog has generated an ID. My code is as follows

router.get("/blog/:id", ensureAuthenticated, (req, res) => {
    let id = req.params.id;
    console.log(`id is ${id}`)
    Blog.findOne({_id: id})
        .then((result) => {
            console.log(`result: ${result}`)
            res.render("viewPost", {
                post: result,
                user: req.user,
            });
        })
        .catch((error) => {
            console.log(error)
        })
});
router.post("/blog-new", (req, res) => {
    const blog = new Blog({
        title: req.body.title,
        snippet: req.body.snippet,
        body: req.body.blog,
    })
    blog.save()
        .then((result) => {
            res.redirect("blog/posted");
        })
        .catch((error) => {
            console.log(error);
        })
})
router.get("/blog/posted", ensureAuthenticated, (req, res) => {
    res.render("blogPosted", {
        user:req.user,
    });
});
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!