2
votes

Good evening everyone,

I would appreciate any help.

I got these two routes:

app.get('/', function(req,res){

        res.render('index');
});

app.get('/registration/add', function(req,res){

        res.render('clientRegistration');
});

and this is part of the server:

app.use( express.static(path.join( __dirname, './client/static/')));
app.use(body_parser.urlencoded());
app.set( "views", path.join(__dirname, "./client/views/"));
app.set( "view engine", 'ejs');

Directory is:

MyApp/
    client/
        static/
            registration.css
            styles.css
        views/
            index.ejs
            clientRegistration.ejs

On my index.ejs, I have: link rel="stylesheet" type="text/css" href="styles.css" which loads the .css file perfectly. But when I click the link: a href="/registration/add"> on index.ejs, it takes me to the clientRegistration.ejs page but the registration.css does not load even though I have: link rel="stylesheet" type="text/css" href="registration.css"

What am I doing wrong?

Thanks for your time.

2

2 Answers

4
votes

Maybe missing / is a problem

<link rel="stylesheet" type="text/css" href="/registration.css">
1
votes

Try to add a forward slash before your style.css href. As it seems to me, everything is setup correctly and it might be only a problem with the current folder reference.