Skip to content

Commit

Permalink
fix: query parameters passing when localePath (#2310)
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Aug 12, 2023
1 parent 5fc06df commit 67ff1ea
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"unplugin": "^1.3.2",
"unstorage": "^1.5.0",
"vue-i18n": "9.3.0-beta.24",
"vue-i18n-routing": "^0.13.1"
"vue-i18n-routing": "^0.13.2"
},
"devDependencies": {
"@babel/parser": "^7.22.7",
Expand Down
13 changes: 6 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions specs/fixtures/issues/2020/app.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
<NuxtPage />
</div>
</template>
12 changes: 12 additions & 0 deletions specs/fixtures/issues/2020/i18n.config.ts
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'
}
}
}))
23 changes: 23 additions & 0 deletions specs/fixtures/issues/2020/nuxt.config.ts
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'
}
})
14 changes: 14 additions & 0 deletions specs/fixtures/issues/2020/package.json
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"
}
}
41 changes: 41 additions & 0 deletions specs/fixtures/issues/2020/pages/index.vue
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>
5 changes: 5 additions & 0 deletions specs/fixtures/issues/2020/pages/some-route.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<template>
<div>
<h1>Some route</h1>
</div>
</template>
23 changes: 23 additions & 0 deletions specs/issues/2020.spec.ts
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')
})
})

0 comments on commit 67ff1ea

Please sign in to comment.