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

321
Views
With res.render("url", {object}) the url doesn't change but the view is changed

I'm building a e-commerce page using express and when i want to delete one of my products everything seems to work fine but the url doesn't change (and it should).

So here is my code:

//route

router.use('/product', require('./product.routes'))

router.delete('/item/:id', productController.deleteProduct);

//controller

 deleteProduct: (req, res) => {
        let id = req.params.id;
        let newDatabase = database.filter((item) => item.id != id);
        fs.writeFileSync(path.join(__dirname, '../database/productos.json'), JSON.stringify(newDatabase, null, 4), {encoding: 'utf-8'});
        let productVisited = newDatabase.filter(item=>item.category=="visited");
        let productInSale = newDatabase.filter(item=>item.category=="in-sale");
        res.render("home", {newDatabase, productVisited, productInSale });
    }
}

//EJS

<form method="POST" action="/product/item/<%= database.id %>?_method=DELETE">
<input type="submit" class="action-button delete" value="ELIMINAR">
</form>

//ENTRY POINT (APP.JS)

const express = require('express');
const path = require('path');
const methodOverride = require ('method-override');
const app = express();
app.use(express.static(path.join(__dirname, "./public")));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.use(methodOverride("_method"));
app.set("view engine", "ejs");
app.set("views",path.join(__dirname, "./src/views"));
app.use("/", require ("./src/routes/index.routes"));
app.use((req, res, next) => {
    res.status(404).render('error')
});
app.listen(process.env.PORT || 3000, () => {
    console.log('Server Running')
})

Thanks in advance for your time! have a nice day

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!