When using Express with EJS, my base route is set as follows:
router.get("/", productsData.getProducts);
The "productsData" is sourced from my controllers page and the code snippet within that page is as follows:
exports.getProducts = (req, res, next) => {
res.render("shop/index", { pageTitle: "Shop", path: "/" });
};
Interestingly, a simple page reload seems to solve the issue and the CSS files are loaded successfully. Here's the CSS import code snippet causing the trouble:
<link rel="stylesheet" href="/css/main.css" />
The problem only occurs when the page is redirected here:
exports.postAddProduct = (req, res, next) => {
const product = new Product(req.body.title);
product.save();
res.redirect("/");
};
Any insights on what might be causing this issue? Could it be related to the res.redirect() function or is it something else?