简体   繁体   中英

Adding and preserving i18n basepath on Routify

I want to use an i18n basepath on Routify.

In other words, my URL is like this: www.example.com/about-us/

And I want to change it to this: www.example.com/[CURRENT_LANGUAGE]/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. But when I change the URL by clicking href it removes the prefix but goes to the desired URL. I need to have the prefix in the new URL as well.

I think I need to change my href s to adopt the new basepath logic. 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 .

GitHub repo:Click here

I tried copy pasting your App.svelte to the starter template, but it works as expected. 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
  • B) use window.location.href = '/en/some/page'

If you're using plain href , you need to include $url . Ie. <a href={$url('/about')>about</a> or <a href="/about" use:$url>about</a> . Otherwise, your URLs won't be rewritten. https://routify.dev/docs/helpers#url

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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