简体   繁体   中英

Node.js loading external stylesheets from Jade, inconsistent path

I am developing a nodejs application using the Jade template engine.

Inside my main("/") layout I have the following code that loads external CSS in my public path.

link(rel='stylesheet', href='/stylesheets/styles.css')
...

there are multiple lines of external javascript and css files to be loaded.

However, When I have to load it from my /users/profile jade template the link is broken.

It says

GET http://localhost:3000/users/javascripts/underscore.js 404 (Not Found) 

Is there a way to have a set of links that works in all of my Jade template so I don't have to manually redefine them everytime?

Thanks in advance, Dennis

If you are using express do it like this:

app.use(express.static(__dirname + '/public'));

link(rel='stylesheet', href='/stylesheets/styles.css') this will make following http request: GET http://localhost:3000/stylesheets/styles.css and express will look for the file in directory: ~/public/stylesheets/styles.css

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