我有一个express.js应用程序当前使用ejs(在较新的项目中使用jade),并且我正在尝试以干净且适当的方式解决问题。
我有一个layout.ejs 文件,其中包含页眉和页脚。到目前为止,我的网站大部分都是一层深的 http://innovationbound.com/about或/services 或/amy 等等......
我开始在 http://innovationbound.com/courses/course-name 创建在线类(class)我遇到的问题是这些类(class)页面无法以相同的方式引用图像。 <img src="images/linknedin.png" alt="LinkedIn Icon">
例如。
从类(class)名称页面尝试 <img src="courses/images/LinkedIn.png" alt="LinkedIn Icon">
显然无法抓取那里的图像。
是否有快速设置,或者我缺少什么明显的东西?我希望我不必使用绝对网址,这只会让本地计算机上的开发变得疯狂。
最佳答案
只需使用站点根目录相对路径。例如<img src="/images/linknedin.png" alt="LinkedIn Icon">
。请注意/
有所作为。
There are three types of link paths:
Absolute paths (such as http://www.adobe.com/support/dreamweaver/contents.html).
Document-relative paths (such as dreamweaver/contents.html).
Site root–relative paths (such as /support/dreamweaver/contents.html).
来自Adobe .
关于node.js - 如何在express.js中引用布局图像以便可以从嵌套目录中找到它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14736981/