在ASAR中找不到PNG文件 [英] PNG files not found in ASAR
问题描述
我有一个Electron(1.7.10)应用程序,报告它在我的ASAR中找不到7个PNG文件中的5个。所有7个PNG都位于同一文件夹中,并且其中2个显示在屏幕上。其他5个报告 net :: ERR_FILE_NOT_FOUND 。
I have an Electron (1.7.10) application that is reporting it can't find 5 of 7 PNG files in my ASAR. All 7 PNGs are in the same folder, and 2 of them are displayed on screen fine. The other 5 report net::ERR_FILE_NOT_FOUND.
img标签的所有src属性都是动态生成的,并使用相对路径( assets / images / MyImage.png
)。如果提取ASAR,则可以在正确的文件夹(由src属性引用)中看到其中的文件。
All src attributes for the img tags are dynamically generated and use relative paths (assets/images/MyImage.png
). If I extract the ASAR, I can see the files in there, in the correct folder (as referenced by the src attribute).
如果我使用控制台将浏览器的位置设置为其中一张图片( document.location.href = file:// /path/to/app.asar/dist/assets/images/MyImage.png
),我得到的结果相同-7之2显示确定。
If I use the console to set the location of my browser to one of the images (document.location.href = "file:///path/to/app.asar/dist/assets/images/MyImage.png"
) I get the same results - 2 of 7 show OK.
在打包我的应用程序(带有电子生成器)之前,所有图像都可以正确显示。
Before packaging my application (with electron-builder), all images show correctly.
有什么想法吗?
谢谢
TTE
推荐答案
让我猜,您正在使用react-router和BrowserRouter构建一个React SPA?
Let me guess, you are building a react SPA using react-router, and BrowserRouter?
如果是,请改用HashRouter。默认情况下,Electron无法使用SPA的路由,因为SPA路由会发生变化,但是资源路径始终是相对于index.html的。
If so, use HashRouter instead. Electron does not work with SPA's route by default, because a SPA route changes, but the resource path is always relative to index.html.
这篇关于在ASAR中找不到PNG文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!