我需要在html页面中包含我的静态图像。所以我这样做:
app.use(express.static(path.join(__dirname, 'public')));
把我所有的图片放在public '/images'文件夹下。然后我这样命名它:
<img src="images/image_1.jpg"/>
但是当页面加载时,我的路径看起来像:
http://localhost:3000/product/images/image_1.jpg
为什么页面url路径http://localhost:3000/product/在img src之前添加?
如果你已经在http://localhost:3000/product
点击链接与href images/image_1.jpg
带你到http://localhost:3000/product/images/image_1.jpg
作为URL是相对的。
您可能想使用绝对路径而不是
<img src="/images/image_1.jpg" />