Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"unplugin": "^1.5.0",
"unstorage": "^1.9.0",
"vue-i18n": "9.5.0",
"vue-i18n-routing": "^1.1.2"
"vue-i18n-routing": "^1.1.4"
},
"devDependencies": {
"@babel/parser": "^7.23.0",
Expand Down
40 changes: 20 additions & 20 deletions pnpm-lock.yaml

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

35 changes: 35 additions & 0 deletions specs/basic_usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,38 @@ test('fallback to target lang', async () => {
// current locale
expect(await getText(page, '#lang-switcher-current-locale code')).toEqual('nl')
})

test('(#2525) localePath should keep hash', async () => {
const { page } = await renderPage('/')

expect(await page.locator('#link-about-hash').getAttribute('href')).toEqual('/about#my-hash')
expect(await page.locator('#link-about-hash-object').getAttribute('href')).toEqual('/about#my-hash')

expect(await page.locator('#link-about-query-hash').getAttribute('href')).toEqual('/about?foo=bar#my-hash')
expect(await page.locator('#link-about-query-hash-object').getAttribute('href')).toEqual('/about?foo=bar#my-hash')

// click `nl` lang switch with `<NuxtLink>`
await page.locator('#switch-locale-path-usages .switch-to-nl a').click()
await waitForURL(page, '/nl')

expect(await page.locator('#link-about-hash').getAttribute('href')).toEqual('/nl/about#my-hash')
expect(await page.locator('#link-about-hash-object').getAttribute('href')).toEqual('/nl/about#my-hash')

expect(await page.locator('#link-about-query-hash').getAttribute('href')).toEqual('/nl/about?foo=bar#my-hash')
expect(await page.locator('#link-about-query-hash-object').getAttribute('href')).toEqual('/nl/about?foo=bar#my-hash')
})

test('(#2523) localePath should not double encode paths', async () => {
const { page } = await renderPage('/')
const encodedPath = encodeURI('page with spaces')

expect(await page.locator('#link-page-with-spaces').getAttribute('href')).toEqual(`/${encodedPath}`)
expect(await page.locator('#link-page-with-spaces-encoded').getAttribute('href')).toEqual(`/${encodedPath}`)

// click `nl` lang switch with `<NuxtLink>`
await page.locator('#switch-locale-path-usages .switch-to-nl a').click()
await waitForURL(page, '/nl')

expect(await page.locator('#link-page-with-spaces').getAttribute('href')).toEqual(`/nl/${encodedPath}`)
expect(await page.locator('#link-page-with-spaces-encoded').getAttribute('href')).toEqual(`/nl/${encodedPath}`)
})
31 changes: 31 additions & 0 deletions specs/fixtures/basic_usage/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,37 @@ useHead({
{{ category.title }}
</NuxtLink>
</li>
<li class="path-hash">
<NuxtLink id="link-about-hash" :to="localePath('/about#my-hash')">{{ $t('about') }}</NuxtLink>
</li>
<li class="path-query-hash">
<NuxtLink id="link-about-query-hash" :to="localePath('/about?foo=bar#my-hash')">
{{ $t('about') }}
</NuxtLink>
</li>
<li class="path-hash">
<NuxtLink id="link-about-hash-object" :to="localePath({ name: 'about', hash: '#my-hash' })">{{
$t('about')
}}</NuxtLink>
</li>
<li class="path-query-hash">
<NuxtLink
id="link-about-query-hash-object"
:to="localePath({ name: 'about', query: { foo: 'bar' }, hash: '#my-hash' })"
>
{{ $t('about') }}
</NuxtLink>
</li>
<li class="path-spaces">
<NuxtLink id="link-page-with-spaces" :to="localePath({ name: 'page with spaces' })">
To the page with spaces!
</NuxtLink>
</li>
<li class="path-spaces-encoded">
<NuxtLink id="link-page-with-spaces-encoded" :to="localePath(`/${encodeURI('page with spaces')}`)">
To the page with spaces!
</NuxtLink>
</li>
</ul>
</section>
<section id="nuxt-link-locale-usages">
Expand Down
3 changes: 3 additions & 0 deletions specs/fixtures/basic_usage/pages/page with spaces.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div>It works</div>
</template>