Next.js & Reader API — Dynamic routes missing on deployed site (Vercel) #950
-
I'm trying Keystatic out for a new project and followed the Next JS tutorial. Not sure if this is a Vercel or Keystatic issue, but the // app/posts/[slug].tsx
const reader = createReader(process.cwd(), keystaticConfig);
export default async function PostPage(params) {
const post = await reader.collections.posts.read(params.slug);
// post is empty when deployed on Vercel!
// but works fine locally
return ...
} Static page routes work fine: // app/posts/static-post.tsx
const reader = createReader(process.cwd(), keystaticConfig);
export default async function PostPage() {
const post = await reader.collections.posts.read('static-post')
// No probs, post has data
return ...
} Using: "@keystatic/core": "^0.3.17"
"@keystatic/next": "^3.0.0"
"next": "14.1.0" I've created a reproduction repo here: https://github.com/unkleho/nextjs-keystatic-test The deployed site is here: https://nextjs-keystatic-test.vercel.app/ Any help on this would be great. Perhaps I've missed a step? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey! Neither a Keystatic nor a Vercel issue — this is a result of building your Next.js site with static pages. Whenever you want to have dynamic path segments (which you do), the HTML pages for each entry need to be generated at build time with If you add this export to your It's pretty easy to do with the Reader API, since all you need to export is an array of Here's an example from the Keystatic docs website, to generate all static docs pages: Hope it helps! |
Beta Was this translation helpful? Give feedback.
-
Is there any way to use Keystatic on Dynamic (server-rendered on demand) pages? (nextjs & vercel) I tried to move content to |
Beta Was this translation helpful? Give feedback.
Hey!
Neither a Keystatic nor a Vercel issue — this is a result of building your Next.js site with static pages.
Whenever you want to have dynamic path segments (which you do), the HTML pages for each entry need to be generated at build time with
generateStaticParams
.If you add this export to your
[slug]
route, the individual post pages will start working.It's pretty easy to do with the Reader API, since all you need to export is an array of
slugs
, which you can get withreader.collections.myCollection.list()
.Here's an example from the Keystatic docs website, to generate all static docs pages:
https://github.com/Thinkmill/keystatic/blob/main/docs/src/app/(public)/docs/%5B...slug%5D/page…