While I am working on a vanilla Javascript project in dev environment with Netlify-cli, I came across a weird issue on parsing relative path.
The situation is like this.
When I click an anchor tag linked to “/projects/colors”, server responds with 404 message. Inspecting the request URL for CSS file was /projects/style.css, not /projects/colors/style.css which I originally expected.
What is interesting is if I change anchor href to “/projects/colors/”(with trailing slash at the end), everything goes fine.
Even when I specify the path of CSS file in an absolute path, everything works so fine.
I cannot figure out why this happens only in dev environment.
I need help understanding why this happens in a nutshell.
├── projects
│ ├── colors
│ │ ├── colorTable.js
│ │ ├── index.html
│ │ ├── main.js
│ │ └── style.css
│ ├── hexcolors
│ │ ├── index.html
│ │ ├── main.js
│ │ └── style.css
│ └── random-quotes
│ ├── index.html
│ ├── main.js
│ └── style.css
├── index.html
├── style.css
└── yarn.lock
/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="./style.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap"
rel="stylesheet"
/>
<title>25 Vannilla JS Projects</title>
</head>
<body>
<main class="App">
<h1>25 Vannilla JS Projects</h1>
<h2>click an image card to navigate our page</h2>
<hr />
<div class="card-list">
<a href="/projects/colors">
<div class="project-card">Colors</div>
</a>
<a href="/projects/hexcolors">
<div class="project-card">CSS Gradient Generator</div>
</a>
<a href="/projects/random-quotes">
<div class="project-card">Random Quotes</div>
</a>
</div>
</main>
<script src="./main.js" type="module"></script>
</body>
</html>
/projects/colors/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" />
<title>Document</title>
</head>
<body>
<main class="App">
<div class="container">
<button
class="btn btn-outline-dark"
id="color-gen-button"
type="button"
>
Click Me!
</button>
</div>
</main>
<script src="main.js" type="module"></script>
</body>
</html>