简体   繁体   English

在 Routify 上添加和保留 i18n 基本路径

[英]Adding and preserving i18n basepath on Routify

I want to use an i18n basepath on Routify.我想在 Routify 上使用 i18n 基本路径。

In other words, my URL is like this: www.example.com/about-us/也就是说,我的 URL 是这样的: www.example.com/about-us/

And I want to change it to this: www.example.com/[CURRENT_LANGUAGE]/about-us/我想把它改成这样: www.example.com/[CURRENT_LANGUAGE]/about-us/ ]/about-us/

I've followed the example provided on the official website but it didn't work for me.我已经按照官方网站上提供的示例进行操作,但它对我不起作用。 When I add the /ru/ or /en/ prefix it works.当我添加/ru//en/前缀时,它可以工作。 But when I change the URL by clicking href it removes the prefix but goes to the desired URL.但是,当我通过单击href更改 URL 时,它会删除前缀,但会转到所需的 URL。 I need to have the prefix in the new URL as well.我还需要在新的 URL 中有前缀。

I think I need to change my href s to adopt the new basepath logic.我认为我需要更改我的href以采用新的基本路径逻辑。 But not sure how to do it.但不知道该怎么做。 How can I solve this issue?我该如何解决这个问题? Any help is very much appreciated.很感谢任何形式的帮助。

My build info: Svelte , Snowpack , Routify , Svelte-i18n .我的构建信息: SvelteSnowpackRoutifySvelte-i18n

GitHub repo:Click here GitHub 回购:点击这里

I tried copy pasting your App.svelte to the starter template, but it works as expected.我尝试将您的App.svelte复制粘贴到入门模板,但它按预期工作。 The language was retained when navigating.导航时保留语言。

If you're trying to change the active language, you have to如果您尝试更改活动语言,则必须

  • A) update the lang value in your App.svelte or A) 更新App.svelte中的lang值或
  • B) use window.location.href = '/en/some/page' B) 使用window.location.href = '/en/some/page'

If you're using plain href , you need to include $url .如果您使用普通的href ,则需要包含$url Ie. IE。 <a href={$url('/about')>about</a> or <a href="/about" use:$url>about</a> . <a href={$url('/about')>about</a><a href="/about" use:$url>about</a> Otherwise, your URLs won't be rewritten.否则,您的 URL 将不会被重写。 https://routify.dev/docs/helpers#url https://routify.dev/docs/helpers#url

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM