Skip to content

Commit 56214b6

Browse files
authored
Merge pull request #144 from codeforIATI/22-nuxtjs-rewrite
Ensure pages with trailing slash display correctly
2 parents 620b1f1 + b1a8837 commit 56214b6

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

β€Žapp/pages/[...slug].vueβ€Ž

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
<script setup lang="ts">
1212
const { t } = useI18n()
13-
import { withLeadingSlash } from 'ufo'
13+
import { withLeadingSlash, joinURL } from 'ufo'
1414
import type { Collections } from '@nuxt/content'
1515
1616
const route = useRoute()
1717
const { locale } = useI18n()
18-
const slug = computed(() => withLeadingSlash(String(route.params.slug)))
18+
const slug = computed(() => Array.isArray(route.params.slug) ? route.params.slug as string[] : [route.params.slug as string])
19+
const path = computed(() => withLeadingSlash(joinURL(...slug.value)))
1920
2021
2122
const main = useStore()
@@ -29,11 +30,11 @@ const codelist = computed(() => { return main.codelists.includes(codelistPageNam
2930
const { data: page } = await useAsyncData(() => `page-${slug.value}-${locale.value}`, async () => {
3031
// Build collection name based on current locale
3132
const collection = ('content_' + locale.value) as keyof Collections
32-
const content = await queryCollection(collection).path(slug.value).first()
33+
const content = await queryCollection(collection).path(path.value).first()
3334
3435
// Optional: fallback to default locale if content is missing
3536
if (!content && locale.value !== 'en') {
36-
return await queryCollection('content_en').path(slug.value).first()
37+
return await queryCollection('content_en').path(path.value).first()
3738
}
3839
3940
return content

0 commit comments

Comments
Β (0)