New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
localizePath and ids #87
Comments
Thank you for the issue, this is a duplicate of #77, so closing this one. |
Hi, I have the same problem here with /#contact which generates http://127.0.0.1:3000/fr/#contact/, could you explain the answer to this problem? return href.startsWith('#') ? href : localizePath(href)? Thank you! |
Hey sure! From what I can see, the only case where adding a <a href="#contact">Link</a> Then you want it to be localized, maybe because it's dynamic so it will become: <a href={localizePath("#contact")}>Link</a> And so it will generate return href.startsWith('#') ? href : localizePath(href) However, if you url is return href.includes('#') ? localizePath(href).splice(-1) : localizePath(href) Let me know if that wasn't clear enough 👍 |
Thank for your quick and precise answer! Where i put this code "return href.startsWith('#') ? href : localizePath(href)"? In my layout.astro where is located my header?
To be transparent i'm still learning js/ts ahah! Thank you 💯 |
I would refactor is a little bit like so: ---
import { localizePath } from 'astro-i18next'
const links = [
{
href: '#solutions',
name: 'Solutions',
},
{
href: '#enfoque',
name: 'Enfoque',
},
{
href: '#nosotros',
name: 'Nosotros',
},
{
href: '/blog',
name: 'Blog',
},
{
href: '#contactanos',
name: 'Contactanos',
active: true,
},
].map(({ href, name, active }) => ({
name,
active,
href: href.startsWith('#') ? href : localizePath(href),
}))
---
<ul
tabindex="0"
class="menu menu-compact dropdown-content bg-base-100 rounded-box mt-3 w-52 p-2 shadow"
>
{
links.map(({ href, name, active }) => (
<li>
<a
class={active ? 'text-primary font-bold' : null}
href={localizePath(href)}
>
{name}
</a>
</li>
))
}
</ul> |
That's great, work for me! Thank you for your time! |
If I am in another page this workaround does not work |
Hi, when using
localizePath
with and id in it (#contact
for instance), it adds an/
at the end. Here is a workaround I've made but not ideal:The text was updated successfully, but these errors were encountered: