Skip to content Skip to sidebar Skip to footer

Css Not Loading With Req.params Or Maybe Something Else

I'm very new to node, express etc. I've made a blog-app and i'm facing a problem. I'm using mongoose, node, express and ejs. When i call router.get('/posts', function(req, res){

Solution 1:

<link rel="stylesheet" href="style.css"> tries to load style.css from the same path where the HTML page is. So, for /posts, it will try loading /style.css and for /posts/1, it will try to load /posts/style.css. But the latter matches your /posts/:posts_id endpoint, so that gets called instead with posts_id == 'style.css', which is nonsensical.

The solution is quite simply to make the link absolute:

<link rel="stylesheet" href="/style.css">

Solution 2:

I was facing the same issue,but finally I solved it. Do Following: In Your HTML or EJS File write: <link rel="stylesheet" href="../style.css">

in head section,it will work for both /post and /post:id

Post a Comment for "Css Not Loading With Req.params Or Maybe Something Else"