I'm using Next.js's new App Router for my portfolio to showcase projects with dynamic routing (src/app/projects/[id]/page.tsx). In development, useSearchParams correctly fetches the project ID, but in production, it returns null, causing my SSG (Static Site Generation) setup to fail in fetching project details.
Since I am semi-new in next.js, I though I can use the way that I use inside the development in production as well.
This is the way that I use to take the id from the query and show the related project based on the taken id:
export default function ProjectPage({ params }: { params: { id: string } }) {
const project = data.find(p => p.id === params.id);
if (!project) {
return <div>Project not found</div>;
}
const Explanation = project.explanation;
return (
{My Jsx Components})
}
Now, I want to migrate from development to production and this is the error I get:
Build error occurred Error: Page "/projects/[id]" is missing "generateStaticParams()" so it cannot be used with "output: export" config. at C:\Users\alish\WebstormProjects\my-website-client\node_modules\next\dist\build\index.js:1241:59 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Span.traceAsyncFn (C:\Users\alish\WebstormProjects\my-website-client\node_modules\next\dist\trace\trace.js:151:20) at async Promise.all (index 6) at async C:\Users\alish\WebstormProjects\my-website-client\node_modules\next\dist\build\index.js:1119:17 at async Span.traceAsyncFn (C:\Users\alish\WebstormProjects\my-website-client\node_modules\next\dist\trace\trace.js:151:20) at async C:\Users\alish\WebstormProjects\my-website-client\node_modules\next\dist\build\index.js:1042:124 at async Span.traceAsyncFn (C:\Users\alish\WebstormProjects\my-website-client\node_modules\next\dist\trace\trace.js:151:20) at async build (C:\Users\alish\WebstormProjects\my-website-client\node_modules\next\dist\build\index.js:348:9) at async main (C:\Users\alish\WebstormProjects\my-website-client\node_modules\next\dist\bin\next:155:5) Collecting page data .
After struggling and search for the solution I found out that I cannot use generateStaticParams() and generateStaticPaths() in App routing (because apparantely it has to be under pages folder)
Then I also tried loader function as well in which I ended up with error again. Can anyone help me what I can do to fix this issue ? PS: I am using NextJs next": "^14.1.1"