Fix params/searchParams types for Next.js app router
This commit is contained in:
@@ -1,25 +1,18 @@
|
|||||||
import { RootPage, generatePageMetadata } from '@payloadcms/next/views';
|
import { RootPage, generatePageMetadata } from '@payloadcms/next/views';
|
||||||
|
import type { Metadata } from 'next';
|
||||||
import config from '../../../../payload.config';
|
import config from '../../../../payload.config';
|
||||||
import { importMap } from '../importMap';
|
import { importMap } from '../importMap';
|
||||||
|
|
||||||
export type PayloadRouteParams = {
|
|
||||||
segments?: string[];
|
|
||||||
};
|
|
||||||
|
|
||||||
export type PayloadRouteSearchParams = {
|
|
||||||
[key: string]: string | string[] | undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
params: PayloadRouteParams;
|
params: Promise<{ segments?: string[] }>;
|
||||||
searchParams: PayloadRouteSearchParams;
|
searchParams: Promise<{ [key: string]: string | string[] | undefined }>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const generateMetadata = (props: Props) => {
|
export const generateMetadata = (props: Props): Promise<Metadata> => {
|
||||||
return generatePageMetadata({
|
return generatePageMetadata({
|
||||||
config,
|
config,
|
||||||
params: Promise.resolve(props.params) as Promise<{ [key: string]: string | string[] }>,
|
params: props.params as Promise<{ [key: string]: string | string[] }>,
|
||||||
searchParams: Promise.resolve(props.searchParams) as Promise<{ [key: string]: string | string[] }>,
|
searchParams: props.searchParams as Promise<{ [key: string]: string | string[] }>,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -27,7 +20,7 @@ export default function Page(props: Props) {
|
|||||||
return RootPage({
|
return RootPage({
|
||||||
config,
|
config,
|
||||||
importMap,
|
importMap,
|
||||||
params: Promise.resolve(props.params) as Promise<{ segments: string[] }>,
|
params: props.params as Promise<{ segments: string[] }>,
|
||||||
searchParams: Promise.resolve(props.searchParams) as Promise<{ [key: string]: string | string[] }>,
|
searchParams: props.searchParams as Promise<{ [key: string]: string | string[] }>,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user