So i have a problem. I want to make a route for example from localhost.../cars to localhost../bmw/x1
I have a button on localhost../cars, after clicking it, site loads localhost../bmw/x1
So have have this code in my javascript:
const express = require("express");
var app = express();
app.use(express.static("public"));
app.set("views", "views");
app.set("view engine", "pug");
app.get('/', (req, res) => {
res.render("firstpage");
});
app.get("/cars", function(req,res){
res.render("cars");
});
app.get("/bmw/x1", function(req,res){
res.render("bmwx1");
});
app.listen(PORT, function() {
console.log("server is running);
});
and this in my pug where the firstpage is:(only a piece of the code)
html
head
link(rel="stylesheet", href="styles/style.css")
link(href="https://fonts.googleapis.com/css2?family=Akshar:wght@300&display=swap" rel="stylesheet")
meta(name="viewport", content="width=device-width, initial-scale=1, maximum-scale=1")
body
nav
h3
a(href="/cars") cars
and then on /cars i have somewhere a button:
div
button(class="detailsbutton")
a(href="/bmw/x1") Details
Now this actually works for me, it loads the pug but if i load into localhost../bmw/x1 my css doesn't work there, only on this path, anywhere it works but not there, so it's not formatted.
So im not sure if i can't just use app.get("/site/secondsite",...) and i have to do this other way or a error is somewhere else
Thanks for answering and sorry for my english!
/bmw/x1tries to load/bmw/styles/style.css, becausehref="styles/style.css"is a relative URL. Make it absolute:href="/styles/style.css".