2

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 Answers 2

5

Maybe missing / is a problem

<link rel="stylesheet" type="text/css" href="/registration.css">
Sign up to request clarification or add additional context in comments.

2 Comments

It works. Thank you so much. I have the href="styles.css" working perfectly without the "/" , but the href="registration.css" was not working without it.
In first situation it worked because you were on / route but in second situation it searched file in` /registration/add/registration.css` route instead of /registration.css. This happens when you forgot to add slash before href
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.