[英]relative path of image gets affected by nested routes in routify
I have a nested route in routify with the below folder structure, where the image is placed in public folder and referred here and I'm using the image in App.svelte.我在 routify 中有一个嵌套路由,具有以下文件夹结构,其中图像放置在公用文件夹中并在此处引用,我正在使用 App.svelte 中的图像。 Everything works fine.
一切正常。 when I go to example.com/1/2 the relative path doesn't work properly
当我 go 到 example.com/1/2 时,相对路径无法正常工作
public
--assets
--images
--image.png
src
--pages
--[aid]
--[bid].svelte
--_layout.svelte
App.svelte
App.svelte App.svelte
<img src="./assets/images/zrx-logo.png" />
this is how I referred to the image in App.svelte这就是我在 App.svelte 中引用图像的方式
ERROR错误
GET http://localhost:5000/1/assets/images/image.png 404 (Not Found) this is how it gets resolved instead of http://localhost:5000/assets/images/image.png. GET http://localhost:5000/1/assets/images/image.png 404(未找到)这是如何解决它而不是 http://localhost:5000/assets/images/image.png。
PS when the URL is example.com/1 the image gets resolved properly PS 当 URL 是 example.com/1 时,图像得到正确解析
You should use an absolute path.您应该使用绝对路径。
./
means the current folder. ./
表示当前文件夹。 thus at http://localhost:5000/1
the current folder is the root of the website which is public
folder which is translated to /public
因此在
http://localhost:5000/1
当前文件夹是网站的根目录,它是被翻译为/public
的public
文件夹
./
at http://localhost:5000/1/2
means /public/1
./
在http://localhost:5000/1/2
表示/public/1
to resolve your issue set the path to /assets/images/zrx-logo.png
this means we start looking for the file directly from the root folder ( /public
)要解决您的问题,请将路径设置为
/assets/images/zrx-logo.png
这意味着我们直接从根文件夹( /public
)开始查找文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.