Skip to content

Instantly share code, notes, and snippets.

@andriilive
Created December 20, 2024 23:04
Show Gist options
  • Save andriilive/efbbc5109aa9a586a2fa6eb7c64167b8 to your computer and use it in GitHub Desktop.
Save andriilive/efbbc5109aa9a586a2fa6eb7c64167b8 to your computer and use it in GitHub Desktop.
Next CatchAllPage bypassing static export errors
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