我有动态页面:
/product/[prod]/page.tsx
这是页面中的代码:
import { ProductJson } from "./productJson";
import ProductJsonSeo from "./ProductJsonSeo";
export async function generateMetadata({
params,
}: {
params: { prod: string; attri: string; page?: number };
}): Promise<Metadata> {
const product = await getProductData(params);
const prod = product.data.product;
const meta = MetaGenerate(
prod.prod_seo_title,
prod.prod_seo_description,
`/product/${ConvertLink(prod.prod_url)}`,
prod.prod_seo_image,
true
);
return meta;
}
const ProductPage = async ({
params,
}: {
params: { prod: string; attri: string; page?: number };
}) => {
const prods = getProductData(params);
const listProd = getListProductData();
const [product, products] = await Promise.all([prods, listProd]);
const data = product.data;
const ProdJson = ProductJson(data);
return (
<div>
<ProductJsonSeo ProdJson={ProdJson} />
<ProductScreen product={product} />
<ProductList
data={products?.data}
/>
</div>
);
};
export default ProductPage;
这是getProduct:
import { ProductNameGetRoute } from "@/components/api";
export async function getProductData(params: {
prod: string;
attri: string;
page?: number;
}) {
const res = await fetch(
`https://www.sample.com/${ProductNameGetRoute(params)}`,
{ cache: "no-store" }
);
return await res.json();
}
我从“ProductJson”中获取Schema,并且它正在工作!
这是ProductJsonSeo中的代码:
import Script from "next/script";
import React from "react";
const ProductJsonSeo = ({ProdJson}: any) => {
return (
<section>
<Script
id="product"
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(ProdJson) }}
/>
</section>
);
};
export default ProductJsonSeo;
我的问题是在生产JSON LD。在localhost中,一切正常!但在生产中不是工作。当我在Google Schema中测试时,我没有结果。有人知道我错在哪里吗?
1条答案
按热度按时间np8igboo1#
我发现了问题,也许这是在帮助别人。Nextjs 13.5应用路由器