mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
Catch all routes
This commit is contained in:
77
app/[locale]/[...slug]/page.tsx
Normal file
77
app/[locale]/[...slug]/page.tsx
Normal file
@@ -0,0 +1,77 @@
|
||||
import DynamicContentManager from 'components/layout/dynamic-content-manager';
|
||||
import { pageQuery } from 'lib/sanity/queries';
|
||||
import { clientFetch } from 'lib/sanity/sanity.client';
|
||||
import type { Metadata } from 'next';
|
||||
import { notFound } from 'next/navigation';
|
||||
|
||||
export const runtime = 'edge';
|
||||
|
||||
export const revalidate = 43200; // 12 hours in seconds
|
||||
|
||||
export async function generateMetadata({
|
||||
params
|
||||
}: {
|
||||
params: { locale: string; slug: string[] };
|
||||
}): Promise<Metadata> {
|
||||
let queryParams = {
|
||||
locale: params.locale,
|
||||
slug: ''
|
||||
};
|
||||
|
||||
if (params.slug.length > 1) {
|
||||
queryParams = {
|
||||
locale: params.locale,
|
||||
slug: `${params.slug.join('/')}`
|
||||
};
|
||||
} else {
|
||||
queryParams = {
|
||||
locale: params.locale,
|
||||
slug: `${params.slug}`
|
||||
};
|
||||
}
|
||||
const page = await clientFetch(pageQuery, queryParams);
|
||||
|
||||
if (!page) return notFound();
|
||||
|
||||
return {
|
||||
title: page.seo?.title || page.title,
|
||||
description: page.seo?.description || page.bodySummary,
|
||||
openGraph: {
|
||||
publishedTime: page.createdAt,
|
||||
modifiedTime: page.updatedAt,
|
||||
type: 'article'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
interface PageParams {
|
||||
params: {
|
||||
locale: string;
|
||||
slug: string[];
|
||||
};
|
||||
}
|
||||
|
||||
export default async function Page({ params }: PageParams) {
|
||||
let queryParams = {
|
||||
locale: params.locale,
|
||||
slug: ''
|
||||
};
|
||||
|
||||
if (params.slug.length > 1) {
|
||||
queryParams = {
|
||||
locale: params.locale,
|
||||
slug: `${params.slug.join('/')}`
|
||||
};
|
||||
} else {
|
||||
queryParams = {
|
||||
locale: params.locale,
|
||||
slug: `${params.slug}`
|
||||
};
|
||||
}
|
||||
|
||||
const page = await clientFetch(pageQuery, queryParams);
|
||||
|
||||
if (!page) return notFound();
|
||||
|
||||
return <DynamicContentManager content={page?.content} />;
|
||||
}
|
Reference in New Issue
Block a user