feat: 接入预览模式(Next.js Draft Mode)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import type { Metadata } from "next";
|
||||
import { getProductBySlug } from "@/services/product.service";
|
||||
import { getPreviewOrFallback } from "@/services/preview.service";
|
||||
import { BlockRenderer } from "@/blocks/BlockRenderer";
|
||||
import type { ProductPageDetail } from "@/types/wagtail";
|
||||
|
||||
interface ProductDetailPageProps {
|
||||
params: Promise<{ slug: string }>;
|
||||
@@ -19,7 +21,11 @@ export default async function ProductDetailPage({
|
||||
params,
|
||||
}: ProductDetailPageProps) {
|
||||
const { slug } = await params;
|
||||
const product = await getProductBySlug(slug).catch(() => null);
|
||||
const product = await getPreviewOrFallback<ProductPageDetail>(
|
||||
"products.productpage",
|
||||
"body,summary",
|
||||
() => getProductBySlug(slug).catch(() => null),
|
||||
);
|
||||
|
||||
if (!product) {
|
||||
notFound();
|
||||
|
||||
Reference in New Issue
Block a user