forked from nuxt-modules/i18n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: custome route path for component with
defineI18nRoute
(nuxt-m…
- Loading branch information
Showing
34 changed files
with
569 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
dist | ||
playground | ||
specs/fixtures | ||
test/fixtures | ||
coverage | ||
docs/components/content/Logo.vue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineBuildConfig } from 'unbuild' | ||
|
||
export default defineBuildConfig({ | ||
externals: ['node:fs', '@intlify/vue-i18n-bridge', 'webpack'] | ||
externals: ['node:fs', 'node:url', '@intlify/vue-i18n-bridge', 'webpack'] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
title: Compiler Macros | ||
description: 'Compiler Macros for `@nuxtjs/i18n`' | ||
--- | ||
|
||
## `defineI18nRoute` | ||
|
||
`defineI18nRoute` is a compiler macro that you can use to set custom route paths for your **page** components located in the `pages/` directory (unless [set otherwise](https://v3.nuxtjs.org/api/configuration/nuxt.config#pages)). This way you can set custom route paths for each static or dynamic route of your Nuxt application. | ||
|
||
```vue [pages/some-page.vue] | ||
<script setup> | ||
defineI18nRoute({ | ||
paths: { | ||
en: '/about-us', | ||
fr: '/a-propos', | ||
ja: '/about-ja' | ||
} | ||
}) | ||
</script> | ||
``` | ||
|
||
## Type | ||
|
||
```ts | ||
defineI18nRoute(route: I18nRoute) => void | ||
|
||
interface I18nRoute { | ||
paths?: Record<Locale, string> | ||
} | ||
``` | ||
|
||
## Parameters | ||
|
||
### `paths` | ||
|
||
- **Type**: `I18nRoute` | ||
|
||
An object accepting the following i18n route settings: | ||
|
||
**`paths`** | ||
|
||
- **Type**: `Record<Locale, string>` | ||
|
||
Customize page component routes per locale. You can specify static and dynamic paths for vue-router. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<template> | ||
<div> | ||
<h1>This is blog page</h1> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
defineI18nRoute({ | ||
paths: { | ||
en: '/blog-us', | ||
fr: '/a-blog', | ||
ja: '/blog-ja' | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { test, expect } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup, url, createPage } from '@nuxt/test-utils' | ||
|
||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/head`, import.meta.url)), | ||
browser: true, | ||
// overrides | ||
nuxtConfig: { | ||
i18n: { | ||
defaultLocale: 'en', | ||
parsePages: true | ||
} | ||
} | ||
}) | ||
|
||
test('can access to custom route path', async () => { | ||
const home = url('/') | ||
const page = await createPage() | ||
await page.goto(home) | ||
|
||
await page.locator('#link-blog').click() | ||
await page.waitForTimeout(1000) | ||
|
||
expect(await page.url()).include('/blog-us') | ||
|
||
await page.goBack() | ||
await page.locator('#lang-switcher-with-nuxt-link a').click() | ||
|
||
await page.locator('#link-blog').click() | ||
await page.waitForTimeout(1000) | ||
|
||
expect(await page.url()).include('/fr/a-blog') | ||
}) | ||
|
||
test('can access to custom dynamic route path', async () => { | ||
const home = url('/') | ||
const page = await createPage() | ||
await page.goto(home) | ||
|
||
await page.locator('#link-category').click() | ||
await page.waitForTimeout(1000) | ||
|
||
expect(await page.url()).include('/categories/foo') | ||
|
||
await page.goBack() | ||
await page.locator('#lang-switcher-with-nuxt-link a').click() | ||
|
||
await page.locator('#link-category').click() | ||
await page.waitForTimeout(1000) | ||
|
||
expect(await page.url()).include(encodeURI('/fr/catégories/foo')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"home": "Homepage", | ||
"about": "About us", | ||
"posts": "Posts" | ||
"posts": "Posts", | ||
"categories": "Categories" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"home": "Accueil", | ||
"about": "À propos", | ||
"posts": "Articles" | ||
"posts": "Articles", | ||
"categories": "Catégories" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<template> | ||
<div> | ||
<h1>This is blog page</h1> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
defineI18nRoute({ | ||
paths: { | ||
en: '/blog-us', | ||
fr: '/a-blog' | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<template> | ||
<div> | ||
<NuxtPage /> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
defineI18nRoute({ | ||
paths: { | ||
en: '/categories/:id', | ||
fr: '/catégories/:id' | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<template> | ||
<div> | ||
<h1>This is category page</h1> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.