Skip to content

Commit c2309c1

Browse files
authored
fix: support passing localized routes to localePath (#3851)
1 parent b40fbbd commit c2309c1

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

specs/fixtures/routing/pages/index.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ const localeRoute = useLocaleRoute()
4949
<span class="external-link">{{ localePath('https://github.com') }}</span>
5050
<span class="external-mail">{{ localePath('mailto:example@mail.com') }}</span>
5151
<span class="external-phone">{{ localePath('tel:+31612345678') }}</span>
52+
53+
<!-- #3840 -->
54+
<span data-testid="current-localized-route-param">{{ localePath($route, 'ja') }}</span>
55+
<span data-testid="object-localized-route-param">{{ localePath({ name: 'index___en'}, 'ja') }}</span>
5256
</section>
5357
<ClientOnly>
5458
<section id="locale-route">

specs/routing/routing-tests.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export async function localePathTests(strategy: Strategies) {
6666
expect(await page.locator('#locale-path .external-mail').innerText()).toEqual('mailto:example@mail.com')
6767
expect(await page.locator('#locale-path .external-phone').innerText()).toEqual('tel:+31612345678')
6868

69+
// (#3840) localized route as parameter
70+
expect(await page.getByTestId('current-localized-route-param').innerText()).toEqual(prefixPath('/', 'ja'))
71+
expect(await page.getByTestId('object-localized-route-param').innerText()).toEqual(prefixPath('/', 'ja'))
72+
6973
// for vue-router deprecation
7074
// https://github.com/vuejs/router/blob/main/packages/router/CHANGELOG.md#414-2022-08-22
7175
expect(consoleLogs.find(log => log.text.includes('Discarded invalid param(s)'))).toBeFalsy()

src/runtime/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function createComposableContext(ctx: NuxtI18nContext, nuxtApp: NuxtApp =
8282
const getLocalizedRouteName = createLocaleRouteNameGetter(defaultLocale)
8383

8484
function resolveLocalizedRouteByName(route: RouteLikeWithName, locale: string) {
85-
route.name ||= getRouteBaseName(router.currentRoute.value) // fallback to current route name
85+
route.name = getRouteBaseName(route.name || router.currentRoute.value) // fallback to current route name
8686

8787
// check if localized variant exists
8888
const localizedName = getLocalizedRouteName(route.name, locale)

0 commit comments

Comments
 (0)