简体   繁体   中英

css not loading property using express .ejs nodejs

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.

也许缺少/是一个问题

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM