Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.7k views
in Technique[技术] by (71.8m points)

Css not loading on node.js generated link

I'm using node.js, express and mysql. I have successfully followed these instructions to include my css file: How can I include css files using node, express, and ejs? The css does load on every page, except one link that contains an id in the url:

http://localhost:8089/edit/123

The last number is passed from the previous page, when the user clicks on an 'edit' link in a table row. The styling is not loading on this edit page. It does load everywhere else. My node.js server file:

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

The edit.html is in the same 'views' folder as the other pages. The css link is the same in the html:

<link rel="stylesheet" href="css/style.css">

Can someone help what the problem is and how to fix it?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

add /

<link rel="stylesheet" href="/css/style.css">

this way it will return to the document root not on here /edit/123/css/style.css


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...