-
-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: routing on prefix_and_default strategy (#2235)
- Loading branch information
Showing
9 changed files
with
103 additions
and
375 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,22 @@ | ||
<template> | ||
<div class="lang-switcher"> | ||
<div id="default-locale">Default locale: {{ selectedLocale === defaultLocale }}</div> | ||
<NuxtLink id="lang-switch" :to="switchLocalePath(availableLocale)">Switch</NuxtLink> | ||
</div> | ||
<div id="content"> | ||
<NuxtPage /> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
const { locale: selectedLocale, defaultLocale, locales } = useI18n() | ||
const switchLocalePath = useSwitchLocalePath() | ||
const availableLocale = computed(() => locales.value.find(locale => locale !== selectedLocale.value)) | ||
</script> | ||
|
||
<style scoped> | ||
.lang-switcher { | ||
margin-bottom: 30px; | ||
} | ||
</style> |
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,4 @@ | ||
export default defineI18nConfig(() => ({ | ||
legacy: false, | ||
locale: 'en' | ||
})) |
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,8 @@ | ||
export default defineNuxtConfig({ | ||
modules: ['@nuxtjs/i18n'], | ||
i18n: { | ||
locales: ['en', 'de'], | ||
defaultLocale: 'en', | ||
strategy: 'prefix_and_default' | ||
} | ||
}) |
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 @@ | ||
{ | ||
"name": "nuxt3-test-issues-2226", | ||
"private": true, | ||
"scripts": { | ||
"build": "nuxt build", | ||
"dev": "nuxt dev", | ||
"generate": "nuxt generate", | ||
"preview": "nuxt preview" | ||
}, | ||
"devDependencies": { | ||
"@nuxtjs/i18n": "latest", | ||
"nuxt": "latest" | ||
} | ||
} |
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,8 @@ | ||
<template> | ||
This is about page. | ||
<NuxtLink id="goto-index" :to="localePath({ name: 'index' })">To home page</NuxtLink> | ||
</template> | ||
|
||
<script setup> | ||
const localePath = useLocalePath() | ||
</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,8 @@ | ||
<template> | ||
This is home page. | ||
<NuxtLink id="goto-about" :to="localePath({ name: 'about' })">To about page</NuxtLink> | ||
</template> | ||
|
||
<script setup> | ||
const localePath = useLocalePath() | ||
</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,29 @@ | ||
import { test, expect, describe } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { setup, createPage, url } from '../utils' | ||
import { getText } from '../helper' | ||
|
||
describe('#2226', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/issues/2226`, import.meta.url)) | ||
}) | ||
|
||
test('navigate on `prefix_and_default`', async () => { | ||
const home = url('/') | ||
const page = await createPage() | ||
await page.goto(home) | ||
|
||
await page.locator('#lang-switch').click() | ||
expect(await getText(page, '#default-locale')).include(`Default locale: false`) | ||
|
||
await page.locator('#goto-about').click() | ||
expect(await getText(page, '#content')).include(`This is about page. To home page`) | ||
|
||
await page.locator('#goto-index').click() | ||
expect(await getText(page, '#content')).include(`This is home page. To about pag`) | ||
|
||
await page.locator('#lang-switch').click() | ||
await page.locator('#goto-about').click() | ||
expect(await getText(page, '#content')).include(`This is about page. To home page`) | ||
}) | ||
}) |
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