#Relative links lead to one directory above
3 messages · Page 1 of 1 (latest)
Hi @small coral. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the information provided in the knowledge sources, I can explain why your relative links are behaving unexpectedly in Astro.
The behavior you're describing is likely related to how Astro handles routing and link generation. According to the Astro Documentation on Routing, when creating links between pages in Astro, you should use a URL path relative to your root domain, not a relative file path.
Here's the relevant quote from the documentation:
"Write standard HTML <a> elements in your Astro pages to link to other pages on your site. Use a URL path relative to your root domain as your link, not a relative file path."
This means that instead of using a relative path like ./baz, you should use an absolute path from the root of your site, such as /foo/bar/baz.
For example:
<a href="/foo/bar/baz">Link to Baz</a>
This approach ensures that your links will work correctly regardless of the current page's location in your site structure.
If you need to generate links dynamically or want to ensure you're using the correct paths, Astro provides helper functions from the astro:i18n module. For instance, you can use the getRelativeLocaleUrl() function to generate correct, localized routes. However, this is more relevant for internationalization purposes and might not be necessary for your specific use case.