You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/content/docs/02.guide/03.custom-paths.md
+38-8Lines changed: 38 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Custom Route Paths
3
3
description: Customize the names of the paths for specific locale.
4
4
---
5
5
6
-
In some cases, you might want to translate URLs in addition to having them prefixed with the locale code. There are two methods of configuring custom paths, through [Module configuration](#module-configuration) or from within each [Page component](#page-component).
6
+
In some cases, you might want to translate URLs in addition to having them prefixed with the locale code. There are two methods of configuring custom paths, through [Module configuration](#module-configuration) or from within each [Page component](#definepagemeta).
7
7
8
8
Which method is used is configured by setting the [`customRoutes` options](/docs/api/options#customroutes) this is set to `'page'`{lang="ts-type"} by default. Using both methods at the same time is not possible.
You can use the `i18n` property in `definePageMeta()`{lang="ts"} to set custom paths for each page component.
189
+
```vue [pages/about.vue]
190
+
<script setup>
191
+
definePageMeta({
192
+
i18n: {
193
+
paths: {
194
+
en: '/about-us', // -> accessible at /about-us (no prefix since it's the default locale)
195
+
fr: '/a-propos', // -> accessible at /fr/a-propos
196
+
es: '/sobre' // -> accessible at /es/sobre
197
+
}
198
+
}
199
+
})
200
+
</script>
201
+
```
202
+
203
+
To configure a custom path for a dynamic route, you need to use it in double square brackets in the paths similar to how you would do it in [Nuxt Dynamic Routes](https://nuxt.com/docs/guide/directory-structure/pages#dynamic-routes):
Note for those updating to `v8.0.1`{lang="sh"} or higher
190
-
:br:br
191
-
Path parameters parsing has been changed to match that of [Nuxt 3](https://nuxt.com/docs/guide/directory-structure/pages#dynamic-routes), you will have to update your custom paths (e.g. `'/example/:param'`{lang="ts-type"} should now be `'/example/[param]'`{lang="ts-type"})
221
+
This method is deprecated in favor of `definePageMeta()`{lang="ts"} and will be removed in v11.
192
222
::
193
223
194
224
You can use the `defineI18nRoute()`{lang="ts"} compiler macro to set custom paths for each page component.
195
225
196
-
```vue{}[pages/about.vue]
226
+
```vue [pages/about.vue]
197
227
<script setup>
198
228
defineI18nRoute({
199
229
paths: {
@@ -205,9 +235,9 @@ defineI18nRoute({
205
235
</script>
206
236
```
207
237
208
-
To configure a custom path for a dynamic route, you need to use it in double square brackets in the paths similarly to how you would do it in [Nuxt Dynamic Routes](https://nuxt.com/docs/guide/directory-structure/pages#dynamic-routes):
238
+
To configure a custom path for a dynamic route, you need to use it in double square brackets in the paths similar to how you would do it in [Nuxt Dynamic Routes](https://nuxt.com/docs/guide/directory-structure/pages#dynamic-routes):
Copy file name to clipboardExpand all lines: docs/content/docs/02.guide/90.migrating.md
+20-1Lines changed: 20 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,10 +10,29 @@ We have upgrade from Vue I18n v10 to v11, this major version bump deprecates the
10
10
11
11
Check the documentation detailing the breaking changes [here](https://vue-i18n.intlify.dev/guide/migration/breaking11.html).
12
12
13
+
### Custom routes via `definePageMeta()`{lang="ts"}
14
+
We have added support for setting custom routes for pages using the `definePageMeta()`{lang="ts"} API, which is now the recommended way to set custom routes for pages.
15
+
This method is enabled by setting `customRoutes: 'meta'`{lang="ts"} in the module options.
16
+
17
+
To migrate from the `defineI18nRoute()`{lang="ts"} macro, you can simply replace it with `definePageMeta()`{lang="ts"} and set the `i18n` property with the same options:
18
+
```vue [pages/about.vue]
19
+
<script setup>
20
+
definePageMeta({
21
+
i18n: {
22
+
paths: {
23
+
en: '/about-us',
24
+
fr: '/a-propos',
25
+
}
26
+
}
27
+
})
28
+
</script>
29
+
```
30
+
31
+
13
32
### Lazy loading
14
33
The `lazy` option has been removed and lazy loading of locale messages is now the default behavior.
### Signature changed for `finalizePendingLocaleChange()`{lang="ts"}
17
36
The function signature for `finalizePendingLocaleChange()`{lang="ts"} has been corrected from `() => Promise<void>`{lang="ts-type"} to `() => void`{lang="ts-type"}.
18
37
This change was made since the function does not rely on any async operations and should not be awaited, and should prevent unnecessary function coloring.
0 commit comments