Reputation: 45
I am writing store and i have a problem with rendering.
I want to have subdomain /category and it's working just find for route like tis
const CategoryOne = ((req, res) =>{
res.render('shop/category');
});
router.get('/category', CategoryOne);
This is working perfect, but when i go on subdomain category/shoes i want to be redirect on /category with parametr shoes
const Category = ((req, res) =>{
const categoryPass = req.params.category;
res.render('shop/category', {
category: categoryPass
});
});
router.get('/category/:category', Category);
and it's not working, should i redirect? When i do it
res.redirect('/category')
Then i dont have category parametr
EDIT: What i have done so far:
const CategoryOne = ((req, res) =>{
const passedCategory = req.session.categorypassed;
req.session.categorypassed = undefined;
console.log(passedCategory);
Product.find((err, response) => {
res.render('shop/category', {
title: 'Test', products: response, category: passedCategory
});
});
});
const Category = ((req, res) =>{
req.session.categorypassed = req.params.category;
res.redirect('/category');
});
The problem is, when i refresh page i dont have this paramets, is there any way to save it?
Upvotes: 1
Views: 76
Reputation: 7658
A better way to handle this is to use a central public directory for your assets and request them with an absolute path, such as /assets/images/logo.png
, instead of a relative path, such as assets/images/logo.png
.
You can read more about relative and absolute paths here
Upvotes: 1