Accessing resources from library modules #593
-
Hey, first of all thanks for such an amazing framework! I originally come from the Android / KMP development, so my question might be a bit dumb since I lack web expertise. I am developing a website using modular (Kobweb libraries) approach. I'd like to have a module that holds all common components like headers, footers etc, and pack separate pages into their own modules. However, I cannot seem to figure out how to access the resources (images) for the shared components from the subroutes. I'm using relative paths, and would like to avoid absolute. Normally, this would be handled by a template engine, but I'm not sure how to achieve this in Kobweb. I think the repro project will save us a lot of words. Steps to reproduce:
You can find the relevant project structure in the attached sample, the kobweb logo is located in Could you please help me out the fix for this situation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Thank you! (Quick tip: before sharing a source zip, run To fix your issue, the path in If (on Chrome at least) you inspect your page with dev tools, go to the Network tab, and refresh the page, you can see this as well: |
Beta Was this translation helpful? Give feedback.
Thank you!
(Quick tip: before sharing a source zip, run
./gradlew clean
as that will remove a lot of build files resulting in a much smaller final download size)To fix your issue, the path in
SharedHeader.kt
should be"/images/kobweb-logo.png"
with a leading slash. Otherwise, your site is trying to find a file at"subfolder/images/kobweb-logo.png"
If (on Chrome at least) you inspect your page with dev tools, go to the Network tab, and refresh the page, you can see this as well: