mirror of
https://github.com/vercel/commerce.git
synced 2025-06-01 14:06:58 +00:00
Fix: Update PageProps for app/content/[slug]/page.tsx
This commit resolves a persistent TypeScript build error: "Type 'ContentPageProps' does not satisfy the constraint 'PageProps'" in `app/content/[slug]/page.tsx`. The `ContentPageProps` interface has been updated to include the `searchParams` property, aligning it with the expected structure for Next.js page components in the App Router. This ensures compatibility with Next.js's internal type definitions for async server components.
This commit is contained in:
parent
fbea7e6d1f
commit
17e5ae33a8
@ -27,26 +27,24 @@ async function getContent(slug: string) {
|
||||
]
|
||||
}
|
||||
};
|
||||
// Ensure slug is a string before using it as an index
|
||||
return allContent[String(slug)] || null;
|
||||
return allContent[slug] || null;
|
||||
}
|
||||
|
||||
// Define an interface for the page's props, with params and searchParams as Promises
|
||||
// Define an interface for the page's props, including searchParams
|
||||
interface ContentPageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
||||
params: {
|
||||
slug: string;
|
||||
};
|
||||
searchParams: { [key: string]: string | string[] | undefined };
|
||||
}
|
||||
|
||||
export default async function ContentPage({ params, searchParams }: ContentPageProps) {
|
||||
// Await the params promise to get its value
|
||||
const resolvedParams = await params;
|
||||
// Await searchParams if you need to use them, e.g.:
|
||||
// const resolvedSearchParams = await searchParams;
|
||||
|
||||
const content = await getContent(resolvedParams.slug);
|
||||
// searchParams is now destructured but not necessarily used if the page doesn't need it.
|
||||
// This is to satisfy the PageProps constraint.
|
||||
const content = await getContent(params.slug);
|
||||
|
||||
if (!content) {
|
||||
return <div>Content not found for {resolvedParams.slug}</div>;
|
||||
return <div>Content not found for {params.slug}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
@ -59,7 +57,7 @@ export default async function ContentPage({ params, searchParams }: ContentPageP
|
||||
);
|
||||
}
|
||||
|
||||
// Optional: Generate static params still works the same way
|
||||
// Optional: Generate static paths if you have a known set of content pages
|
||||
// export async function generateStaticParams() {
|
||||
// return [{ slug: 'about-us' }, { slug: 'contact-us' }, { slug: 'privacy-policy' }];
|
||||
// }
|
||||
|
Loading…
x
Reference in New Issue
Block a user