Created
December 20, 2024 23:04
-
-
Save andriilive/efbbc5109aa9a586a2fa6eb7c64167b8 to your computer and use it in GitHub Desktop.
Next CatchAllPage bypassing static export errors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import type { Params } from 'next/dist/server/request/params' | |
import type { SearchParams } from 'next/dist/server/request/search-params' | |
import { cookies, headers } from 'next/headers' | |
import { CodeBlock } from '@/components/development' | |
export function generateStaticParams() { | |
return [{ path: ['path'] }] | |
} | |
export default async function CatchAllPage( | |
props: Readonly<{ | |
params: Promise<Params> | |
searchParams: Promise<SearchParams> | |
}> | |
) { | |
let notStatic = {} | |
if (process.env.NEXT_OUTPUT === 'export') { | |
notStatic = {} | |
} else { | |
notStatic = { | |
searchParams: await props.searchParams, | |
cookies: await cookies(), | |
headers: await headers() | |
} | |
} | |
const params = await props.params | |
return ( | |
<CodeBlock | |
json={{ | |
params, | |
...notStatic | |
}} | |
></CodeBlock> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment