Preview with the draft page
To preview an article before publishing, use the /news/draft/[id] route. The preview URL from the microCMS dashboard includes a draftKey; pass it to this page to display the draft content.
Simple fetch pattern
Fetch the list and the detail like this for clarity and draft support:
// Fetch News List
const { data: newsList, pending: newsPending } = await useFetch("/api/list", {
query: { endpoint: "news", limit: "3", orders: "-publishedAt" },
})
// Fetch News Detail (draftKey from URL query)
const { data: newsDetail, pending: newsDetailPending } = useFetch("/api/article", {
query: {
endpoint: "news",
contentId: route.params.id,
draftKey: route.query.draftKey,
},
})Notes
- Pass
route.params.idascontentId - Pass
route.query.draftKeyasdraftKey(from the microCMS preview link) - Use
await useFetchfor the list; for the detail, useuseFetchwith acomputedquery so it refetches when the route changes
You can reuse this pattern for both the published article page and the draft preview page.