-
-
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: query parameters passing when localePath (#2310)
- Loading branch information
Showing
9 changed files
with
130 additions
and
8 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,5 @@ | ||
<template> | ||
<div> | ||
<NuxtPage /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export default defineI18nConfig(() => ({ | ||
legacy: false, | ||
locale: 'en', | ||
messages: { | ||
en: { | ||
welcome: 'Welcome' | ||
}, | ||
fr: { | ||
welcome: 'Bienvenue' | ||
} | ||
} | ||
})) |
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,23 @@ | ||
// https://v3.nuxtjs.org/api/configuration/nuxt.config | ||
export default defineNuxtConfig({ | ||
modules: ['@nuxtjs/i18n'], | ||
|
||
i18n: { | ||
vueI18n: './i18n.config.ts', // if you are using custom path, default | ||
locales: [ | ||
{ | ||
code: 'fr', | ||
name: 'Français', | ||
iso: 'fr-BE' | ||
}, | ||
{ | ||
code: 'en', | ||
name: 'English', | ||
iso: 'en-US' | ||
} | ||
], | ||
dynamicRouteParams: true, | ||
defaultLocale: 'fr', | ||
strategy: 'prefix' | ||
} | ||
}) |
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-2020", | ||
"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,41 @@ | ||
<template> | ||
<div> | ||
<h1>{{ $t('welcome') }}</h1> | ||
<h2>Existing path</h2> | ||
<dl> | ||
<dt>Path:</dt> | ||
<dd>{{ path }}</dd> | ||
<dt>Localised path:</dt> | ||
<dd id="existing">{{ localePath(path) }}</dd> | ||
<dt>Router resolve from string:</dt> | ||
<dd>{{ resolvedPathFromString }}</dd> | ||
<dt>Router resolve from object:</dt> | ||
<dd>{{ resolvedPathFromObject }}</dd> | ||
</dl> | ||
|
||
<h2>Unexisting path</h2> | ||
<dl> | ||
<dt>Path:</dt> | ||
<dd>{{ wrong_path }}</dd> | ||
<dt>Localised path:</dt> | ||
<dd id="unexisting">{{ localePath(wrong_path) }}</dd> | ||
<dt>Router resolve from string:</dt> | ||
<dd>{{ resolvedWrongPathFromString }}</dd> | ||
<dt>Router resolve from object:</dt> | ||
<dd>{{ resolvedWrongPathFromObject }}</dd> | ||
</dl> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
const router = useRouter() | ||
const localePath = useLocalePath() | ||
const path = '/some-route?foo=bar' | ||
const resolvedPathFromString = router.resolve(path) | ||
const resolvedPathFromObject = router.resolve({ path }) | ||
const wrong_path = '/i-dont-exist?foo=bar' | ||
const resolvedWrongPathFromString = router.resolve(wrong_path) | ||
const resolvedWrongPathFromObject = router.resolve({ path: wrong_path }) | ||
</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>Some route</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { test, expect, describe } from 'vitest' | ||
import { fileURLToPath } from 'node:url' | ||
import { URL } from 'node:url' | ||
import { setup, url, createPage } from '../utils' | ||
import { getText } from '../helper' | ||
|
||
describe('#2020', async () => { | ||
await setup({ | ||
rootDir: fileURLToPath(new URL(`../fixtures/issues/2020`, import.meta.url)) | ||
}) | ||
|
||
test('pass query parameter', async () => { | ||
const home = url('/') | ||
const page = await createPage() | ||
await page.goto(home) | ||
|
||
const existingPath = await getText(page, '#existing') | ||
const unexistingPath = await getText(page, '#unexisting') | ||
|
||
expect(existingPath).toBe('/fr/some-route?foo=bar') | ||
expect(unexistingPath).toBe('/i-dont-exist?foo=bar') | ||
}) | ||
}) |