Welcome to OStack Knowledge Sharing 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 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...