Skip to content

Commit

Permalink
feat: implement makeswift app router localization
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewvolk committed Jun 21, 2024
1 parent f7e9ebe commit 679d0b1
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/[locale]/(default)/[...rest]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Page as MakeswiftPage } from '@makeswift/runtime/next';
import { getSiteVersion } from '@makeswift/runtime/next/server';
import { notFound } from 'next/navigation';

import { locales } from '~/i18n';
import { client } from '~/makeswift/client';
import { MakeswiftProvider } from '~/makeswift/provider';

Expand All @@ -13,16 +14,20 @@ interface CatchAllParams {
export async function generateStaticParams() {
const pages = await client.getPages().toArray();

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

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

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

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

0 comments on commit 679d0b1

Please sign in to comment.