Skip to content

getLocalePath

Allows you get the right url for the current locale. It’s strictly typed and even requires you to pass parameters as needed.

1
---
2
// Assuming:
3
// 1. stragegy is set to "prefixExceptDefault"
4
// 2. The request page is /fr/my-page
5
import { getLocalePath } from "i18n:astro"
6
7
// Routes defined in the integration config
8
/* /fr */
9
getLocalePath("/")
10
/* /fr/a-propos */
11
getLocalePath("/about")
12
/* /fr/le-blog/hello-world */
13
getLocalePath("/blog/[slug]", { slug: "hello-world" })
14
/* /about */
15
getLocalePath("/about", null, "en")
16
17
// Routes not defined in the integration config
18
/* /fr/abc */
19
getLocalePath("/abc")
20
/* /def */
21
getLocalePath("/def", null, "en")
22
---