Skip to content

Commit

Permalink
⚡️ (next) Dynamic APIs are Asynchronous
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwoerpel committed Jan 23, 2025
1 parent a208752 commit 59fb4a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion _api/draft/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function GET(request: Request) {
return new Response("Invalid id", { status: 401 });
}

draftMode().enable();
(await draftMode()).enable();

return new Response(null, {
status: 307,
Expand Down
22 changes: 12 additions & 10 deletions app/[...slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ type IParams = {
readonly slug?: string[];
};

export async function generateMetadata({
params,
}: {
params: IParams;
}): Promise<Metadata> {
export async function generateMetadata(
props: {
params: Promise<IParams>;
}
): Promise<Metadata> {
const params = await props.params;
const data = await getPage(params.slug || ["index"]);
return {
title: `${data.title}${DEFAULT_TITLE}`,
Expand All @@ -28,11 +29,12 @@ const getPageMenu = (screens: IScreen[]): IPageMenuItem[] =>
.filter(({ item }) => !!item.anchor)
.map(({ item }) => ({ label: item.name, href: `#${slugify(item.name)}` }));

export default async function SlugPage({
params,
}: {
params: { slug: string[] };
}) {
export default async function SlugPage(
props: {
params: Promise<{ slug: string[] }>;
}
) {
const params = await props.params;
if (params.slug.length === 1 && params.slug[0] === "index") {
return permanentRedirect("/");
}
Expand Down
11 changes: 6 additions & 5 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ type IParams = {
readonly slug?: string[];
};

export async function generateMetadata({
params,
}: {
params: IParams;
}): Promise<Metadata> {
export async function generateMetadata(
props: {
params: Promise<IParams>;
}
): Promise<Metadata> {
const params = await props.params;
const data = await getPage(params.slug || ["index"]);
return {
title: `${data.title}${DEFAULT_TITLE}`,
Expand Down

0 comments on commit 59fb4a5

Please sign in to comment.