-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
generateStaticParams
not Passing Parent Params to Child in Nested Dynamic Routes
#53717
Comments
This problem also happened in my project which has the following environment.
What I want to do is like this: // app/tags/[tag]/page.tsx
export const generateStaticParams = async (): Promise<{ tag: string }[]> => {
const tags = await getTags(); // ['tagA', 'tagB', 'tagC']
return tags.map((tag) => ({ tag }));
};
// app/tags/[tag]/page/[pageNumber]/page.tsx
export const generateStaticParams = async ({
params: { tag },
}: {
params: { tag: string };
}): Promise<{ pageNumber: string }[]> => {
// Since tag is always undefined, getting articles by tag is to fail.
const articles = await getArticlesByTag(tag);
// ...
}));
}; |
Same issue. I've also tried to add |
Can we get any updates on a temporary workaround on this issue? I'm having the same issue |
I found a workaround, which is to use generateStaticParams in the layout-file instead of page in the parent folder (template file does not work either). See this repo for an example: https://github.com/viktorronnback/generate-static-params-bug-53717 I'll keep looking into why this bug happens and try to make a PR. I assume it is a bug as, to my knowledge, it isn't stated in the docs that using layout in the parent is a requirement to pass params to child generateStaticParams functions. And even if it was a requirement, I think there should be some sort of build warning about using it. |
@viktorronnback As far as I've been trying, the bottom up pattern has no problem. |
Anyone that might be pulling their hair. the workaround introduces issues with |
For me, the workaround isn't working, next 14.1 |
Next 14.2.5 - pages in a nested route are not generated as well. |
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64 Binaries: Node: 18.12.1 npm: 9.7.1 Yarn: 1.22.19 pnpm: 8.6.6 Relevant Packages: next: 13.4.14-canary.0 eslint-config-next: 13.4.13 react: 18.2.0 react-dom: 18.2.0 typescript: 5.1.6 Next.js Config: output: N/A
Which area(s) of Next.js are affected? (leave empty if unsure)
App Router
Link to the code that reproduces this issue or a replay of the bug
https://github.com/nikolailehbrink/generateStaticParams-Bug
To Reproduce
Describe the Bug
I encountered a bug when using the generateStaticParams function with nested dynamic routes in Next.js. The parent's parameters are not being passed to the child's generateStaticParams, causing unexpected behavior in the generated static pages. According to the your documentation, the expected behavior is to "Generate the parent segments first and use the result to generate the child segments." However, in the provided example, the behavior is not consistent with this documentation, and the slug parameter from the parent route does not get passed to the child.
Expected Behavior
Expected Behavior:
The slug parameter generated in the parent's generateStaticParams should be available in the child's generateStaticParams.
Which browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
NEXT-1509
The text was updated successfully, but these errors were encountered: