Trying to statically generate a dynamic route with the App Router
Answered
Vesper Sparrow posted this in #help-forum
Vesper SparrowOP
Hi, I'm using the
I've set my config
and I've added the following in the page component:
However, it keeps building as a server-side route when I run
Note, trying to log the
Can you help me, please? What am I missing?
/app directory. I have a route /store/[id] that I'm trying to generate a static build of.I've set my config
const nextConfig = {
output: "export",
}and I've added the following in the page component:
export const generateStaticParams = () => [{ id: "test" }]
export default function Page({ params }: { params: { id: string } }) {
const id = params.id
...
}However, it keeps building as a server-side route when I run
next build:λ /store/[id]Note, trying to log the
params variable gives:{ id: '%5Bid%5D' } // which is basically [id], instead of getting substituted with the values I'm providing in generateStaticParamsCan you help me, please? What am I missing?
Answered by Vesper Sparrow
Turns out the issue was that I had "use client" on top of the page. Now that I turned the page back into a server component it works 🎉
3 Replies
@joulev try adding `export const dynamicParams = false`
Vesper SparrowOP
Thank you, but that didn't work either
Vesper SparrowOP
Turns out the issue was that I had "use client" on top of the page. Now that I turned the page back into a server component it works 🎉
Answer