Skip to content

Commit

Permalink
fix: custom routes not working for nested pages from layers (#2555)
Browse files Browse the repository at this point in the history
  • Loading branch information
BobbieGoede committed Nov 19, 2023
1 parent 1616839 commit ee5fc28
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions specs/basic_usage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ test('layer provides locale `nl` and translation for key `hello`', async () => {
const { page } = await renderPage('/layer-page')

expect(await getText(page, '#i18n-layer-target')).toEqual('Hello world!')
expect(await page.locator('#i18n-layer-parent-link').getAttribute('href')).toEqual('/layer-parent')
expect(await page.locator('#i18n-layer-parent-child-link').getAttribute('href')).toEqual('/layer-parent/layer-child')

await gotoPath(page, '/nl/layer-page')
expect(await getText(page, '#i18n-layer-target')).toEqual('Hallo wereld!')
expect(await page.locator('#i18n-layer-parent-link').getAttribute('href')).toEqual('/nl/layer-ouder')
expect(await page.locator('#i18n-layer-parent-child-link').getAttribute('href')).toEqual('/nl/layer-ouder/layer-kind')
})

test('layer vueI18n options provides `nl` message', async () => {
Expand Down
11 changes: 10 additions & 1 deletion specs/fixtures/layers/layer-lazy/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export default defineNuxtConfig({
file: 'nl.json',
name: 'Nederlands'
}
]
],
customRoutes: 'config',
pages: {
'layer-parent': {
nl: '/layer-ouder'
},
'layer-parent/layer-child': {
nl: '/layer-ouder/layer-kind'
}
}
}
})
7 changes: 7 additions & 0 deletions specs/fixtures/layers/layer-lazy/pages/layer-page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<div id="i18n-layer-target">
{{ $t('hello') }}
</div>
<div>
<NuxtLink id="i18n-layer-parent-link" :to="localePath('/layer-parent')">Layer parent page</NuxtLink>
<NuxtLink id="i18n-layer-parent-child-link" :to="localePath('/layer-parent/layer-child')">
Layer parent-child page
</NuxtLink>
</div>
<div>
{{ switchLocalePath('nl') }}
{{ switchLocalePath('fr') }}
Expand All @@ -13,5 +19,6 @@

<script setup>
const switchLocalePath = useSwitchLocalePath()
const localePath = useLocalePath()
// const { locales } = useI18n()
</script>
3 changes: 3 additions & 0 deletions specs/fixtures/layers/layer-lazy/pages/layer-parent.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div></div>
</template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<div></div>
</template>
2 changes: 1 addition & 1 deletion src/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export function analyzeNuxtPages(ctx: NuxtPageAnalyzeContext, pages: NuxtPage[],

if (page.children && page.children.length > 0) {
ctx.stack.push(page.path)
analyzeNuxtPages(ctx, page.children)
analyzeNuxtPages(ctx, page.children, pageDirOverride)
ctx.stack.pop()
}
}
Expand Down

0 comments on commit ee5fc28

Please sign in to comment.