Catch-all routes and SSG
See original GitHub issue@dpfavand in that case you’ll want to use a catch-all route: https://nextjs.org/blog/next-9-2#catch-all-dynamic-routes
Potentially we can warn when you try to return a path including slashes, but the behavior is correct when using
[slug].js, in your case you want[...slug].js.
@timneutkens thanks for the follow-up. I’ve tried two methods without success. Basically when specifying the slug value as a string in getStaticPaths, it isn’t passed through to getStaticProps at all. When returning the slug value as an array, the build fails as the value must be a string.
Case 1, Assuming a file pages/[...slug].jsx, slug as string:
export async function unstable_getStaticPaths() {
return [{ params: { slug: 'en/about' } }];
}
export async function unstable_getStaticProps({ params }) {
console.log('params', params);
return { slug: params.slug };
}
In the above case, params in getStaticProps is an empty object - no slug key.
Case 2, pages/[...slug].jsx, slug as array,
export async function unstable_getStaticPaths() {
const allPaths = Object.keys(pathMap).map(slug => ({ params: { slug } }));
return [{ params: { slug: ['en', 'about'] } }];
}
export async function unstable_getStaticProps({ params }) {
console.log('params', params);
return { slug: params.slug };
}
In case 2, the build fails with
> Build error occurred
{ Error: A required parameter (slug) was not provided as a string.
at _validParamKeys.forEach.validParamKey (/project/node_modules/next/dist/build/utils.js:21:569)
at Array.forEach (<anonymous>)
at toPrerender.forEach.entry (/project/node_modules/next/dist/build/utils.js:21:495)
at Array.forEach (<anonymous>)
at Object.isPageStatic (/project/node_modules/next/dist/build/utils.js:17:122)
at process._tickCallback (internal/process/next_tick.js:68:7) type: 'Error' }
_Originally posted by @dpfavand in https://github.com/zeit/next.js/issues/9524#issuecomment-576344026_
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)

Top Related StackOverflow Question
I’m having similar issue today. In development it runs well, but when building production. In my catch-all-routes component that I generate static paths for, the
router.queryobject is empty on first run.Having similar issue as @eagor described, but without catch-all-routes