1

I am making a Web Project using NodeJS and in which I'm linking to the stylesheet in the header file, which I've included in all of my EJS files

The location of the header file is as follows

root -> views -> partials -> header.ejs

The location of the stylesheet is as follows

root -> public -> style.css

I've used this line to link with the stylesheet in the header.ejs file

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

Now, this stylesheet is being rendered in all pages, except for one. Path of page where the stylesheet isn't working :-

  • /campgrounds/:id/edit

Other pages (where style.css is working properly) :-

  • /campgrounds
  • /campgrounds/new
  • /campgrounds/:id

What is the reason behind this and how to solve this

Cyborg7459
  • 157
  • 3
  • 10

1 Answers1

1

Best practice for linking to resources is to use absolute pathing which means start at the root and work up the structure.

By using / it will start at the root of your application directory.

<link rel="stylesheet" href="/public/style.css">
Papa
  • 1,628
  • 1
  • 11
  • 16