Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
node.js/express javascript route css problem

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!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda