ejs 文件中带有 '/' 的 CSS 链接 href 路径

标签 css node.js http express ejs

图 1:为公用文件夹设置 express.static

图 2:在 post.ejs 中设置 href="/app.css"

图 3:结果

我尝试在 post.ejs 中使用 /app.cssapp.css

结果和第三张图一样

那是不是说我设置好之后

app.use(express.static("public"));

在 app.js 中,静态文件的根路径将是 /public?

因此

绝对路径/app.css 和

相对路径 app.css

是一样的吗?

谢谢

enter image description here

enter image description here

enter image description here

最佳答案

作为您的设置,public 是根文件夹。 您可以通过“app.css”和“/app.css”两种方式调用app.css。他们都在当前根文件夹中获取文件 app.css -> 我认为他们是一样的。

关于ejs 文件中带有 '/' 的 CSS 链接 href 路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38908705/

相关文章:

http - 如何通过 http url 发送二进制数据(del 和 null 字符)

css - 如何在网格显示中将边框应用到每一行的顶部?

node.js - fastify中如何组织路由?

javascript - 在 express.js 中修改请求对象是不好的做法吗?

node.js - 为 Node.js TCP 服务器创建 REST API 包装器

c# - 如何对文件名进行编码以供下载?

html - 如何对齐我的 HTML 页面组件?

html - CSS网格中的重叠图像

CSS3 :not() selector ignored by IE9

api - 请求模块出错