Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(<ContentList>): respect query.path when path is missing #1598

Merged
merged 1 commit into from
Oct 13, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>