Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions playground/document-driven/content/0.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ description: Hello, here is a description
# Home

Hello World!

[404](/404)
13 changes: 5 additions & 8 deletions src/runtime/pages/document-driven.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<script setup lang="ts">
import { createError } from 'h3'
import { useContent, useContentHead, useRoute } from '#imports'
import { useContent, useContentHead, useRequestEvent } from '#imports'

const { page } = useContent()

// Page not found
if (!page.value) {
throw createError({
statusCode: 404,
statusMessage: `Page not found: ${useRoute().path}`
})
// Page not found, set correct status code on SSR
if (!page.value && process.server) {
const event = useRequestEvent()
event.res.statusCode = 404
}

useContentHead(page)
Expand Down
2 changes: 1 addition & 1 deletion test/document-driven.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('fixtures:document-driven', async () => {
await $fetch('/page-not-found')
} catch (e) {
expect(e.response.status).toBe(404)
expect(e.response.statusText).toBe('Page not found: /page-not-found')
expect(e.response.statusText).toBe('Not Found')
}
})
})