Skip to content

Commit

Permalink
feat: render makeswift pages in catch-all route
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewvolk committed Jun 21, 2024
1 parent e5486cc commit 059a7bf
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions app/[locale]/(default)/[...rest]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
import { Page as MakeswiftPage } from '@makeswift/runtime/next';
import { getSiteVersion } from '@makeswift/runtime/next/server';
import { notFound } from 'next/navigation';

export default function CatchAllPage() {
notFound();
import { client } from '~/makeswift/client';

interface CatchAllParams {
locale: string;
rest: string[];
}

export async function generateStaticParams() {
const pages = await client.getPages();

return pages.map((page) => ({
path: page.path.split('/').filter((segment) => segment !== ''),
}));
}

export default async function Page({ params }: { params: CatchAllParams }) {
const path = `/${params.rest.join('/')}`;

const snapshot = await client.getPageSnapshot(path, {
siteVersion: getSiteVersion(),
});

if (snapshot == null) return notFound();

return <MakeswiftPage snapshot={snapshot} />;
}

0 comments on commit 059a7bf

Please sign in to comment.