Skip to content

Commit

Permalink
fix(<ContentList>): respect query.path when path is missing (#1598
Browse files Browse the repository at this point in the history
)
  • Loading branch information
farnabaz committed Oct 13, 2022
1 parent b455d0c commit 4a2937c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/runtime/components/ContentList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default defineComponent({
path: {
type: String,
required: false,
default: '/'
default: undefined
},
/**
Expand All @@ -44,7 +44,10 @@ export default defineComponent({
const { path, query } = ctx
// Merge local `path` props and apply `findOne` query default.
const contentQueryProps = Object.assign(query || {}, { path })
const contentQueryProps = {
...query || {},
path: path || query?.path || '/'
}
const emptyNode = (slot: string, data: any) => h('pre', null, JSON.stringify({ message: 'You should use slots with <ContentList>', slot, data }, null, 2))
Expand Down
7 changes: 7 additions & 0 deletions test/features/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ export const testComponents = () => {
expect(index).toContain('Lorem ipsum dolor sit, amet consectetur adipisicing elit.')
})
})

describe('<ContentList>', () => {
test('custom query', async () => {
const index = await $fetch('/dogs-list')
expect(index).toContain('[Bulldog,German Shepherd]')
})
})
}
20 changes: 20 additions & 0 deletions test/fixtures/basic/pages/dogs-list.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script setup lang="ts">
const query = {
path: '/dogs',
limit: 10,
where: {
_partial: false
}
}
</script>

<template>
<ContentList :query="query">
<template #default="{ list }">
[{{ list.map(i => i.title).join(',') }}]
</template>
<template #not-found>
<p>No articles found</p>
</template>
</ContentList>
</template>

0 comments on commit 4a2937c

Please sign in to comment.