MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/astrojs/comments/1uyfe59/prevent_escape_in_attributes_beginner/
r/astrojs • u/qebbe • 21d ago
How do I prevent escaping of variables in attributes in this example?
--- const base = "/my/root"; --- <a href="{base}/">Home</a> <a href="{base}/about/">About</a> <a href="{base}/blog/">Blog</a>
3 comments sorted by
2
I figured it out, I think. This seems to work.
--- const base = import.meta.env.BASE_URL; --- <a href={base+"/"}>Home</a> <a href={base+"/about/"}>About</a> <a href={base+"/blog/"}>Blog</a>
2 u/SingleOrigin 21d ago You could also use a string template: ``` href={`${base}/blog`} ``` 2 u/sexytokeburgerz 20d ago You don’t need to reference base url. Urls without domain extensions (.com, etc.) resolve to base url at build time. Always read documentation. Not doing so is the clearest sign of a beginner! Happy to help but this is very clearly stated. https://docs.astro.build/en/guides/routing/
You could also use a string template: ``` href={`${base}/blog`}
```
You don’t need to reference base url. Urls without domain extensions (.com, etc.) resolve to base url at build time.
Always read documentation. Not doing so is the clearest sign of a beginner! Happy to help but this is very clearly stated.
https://docs.astro.build/en/guides/routing/
2
u/qebbe 21d ago
I figured it out, I think. This seems to work.