Feature Request: Include `generateStaticParams` Function in Generated `layout.tsx` Files
Closed this issue ยท 1 comments
Feature Request: Include generateStaticParams
Function in Generated layout.tsx
Files
Description
There is an issue in the current version of the package where the generateStaticParams
function is not being included in the generated layout.tsx
files. This function is useful for specifying static parameters direclty from layout in Nextjs app router.
Steps to Reproduce
- Create a new nextjs application with
npx create-next-app
- Install
next-roots
and its dependencies - Provide a basic
roots.config.js
file - Move
src/app/layout.tsx
andsrc/app/page.tsx
undersrc/roots/
- Create a
layout.tsx
file under asrc/roots/[category]
directory. - Export a
generateStaticParams
function from thelayout.tsx
file. - Use the package to generate files under the
src/app/
directory.
Example:
roots.config.js
const path = require('path')
module.exports = {
originDir: path.resolve(__dirname, 'src/roots'),
localizedDir: path.resolve(__dirname, 'src/app'),
locales: ['en', 'cs'],
defaultLocale: 'en',
prefixDefaultLocale: false, // serves "en" locale on / instead of /en
}
src/roots/[category]/layout.tsx
export default function CategoryLayout({ children }: { children: React.ReactNode }) {
return <>{children}</>
}
export async function generateStaticParams(props: any) {
return [{ category: 'a' }, { category: 'b' }]
}
Generated src/app/(en)/[category]/layout.tsx
import CategoryLayoutOrigin from '../../../roots/[category]/layout'
export default function CategoryLayout(props:any) {
{/* @ts-ignore */}
return <CategoryLayoutOrigin {...props} locale="en" />
}
// `generateStaticParams` function is missing here
Expected Behavior
The generateStaticParams
function should be included in the generated layout.tsx
files.
Expected Generated src/app/(en)/[category]/layout.tsx
import CategoryLayoutOrigin from '../../../roots/[category]/layout'
export default function CategoryLayout(props:any) {
{/* @ts-ignore */}
return <CategoryLayoutOrigin {...props} locale="en" />
}
import { generateStaticParams as generateStaticParamsOrigin } from '../../../roots/[category]/layout'
export async function generateStaticParams() {
return generateStaticParamsOrigin({ locale: 'en' })
}
Environment
- Package version: 3.8.0
- Nextjs version: 14.2.5
Proposed Solution
Include the generateStaticParams
function from the original layout.tsx
file in the generated layout.tsx
files.
Pull Request
I work on a PR for this.
Additional Context
Related to Issue #242
Feel free to reach out if you need any additional information or clarification regarding this issue.
๐ This issue has been resolved in version 3.9.0 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐