mirror of
https://github.com/vercel/commerce.git
synced 2025-05-17 15:06:59 +00:00
Update [slug].tsx
This commit is contained in:
parent
2805323513
commit
7748d885cc
@ -14,47 +14,40 @@ export async function getStaticProps({
|
|||||||
locales,
|
locales,
|
||||||
preview,
|
preview,
|
||||||
}: GetStaticPropsContext<{ slug: string }>) {
|
}: GetStaticPropsContext<{ slug: string }>) {
|
||||||
try {
|
const config = { locale, locales }
|
||||||
const config = { locale, locales }
|
const pagesPromise = commerce.getAllPages({ config, preview })
|
||||||
const pagesPromise = commerce.getAllPages({ config, preview })
|
const siteInfoPromise = commerce.getSiteInfo({ config, preview })
|
||||||
const siteInfoPromise = commerce.getSiteInfo({ config, preview })
|
const productPromise = commerce.getProduct({
|
||||||
const productPromise = commerce.getProduct({
|
variables: { slug: params!.slug },
|
||||||
variables: { slug: params!.slug },
|
config,
|
||||||
config,
|
preview,
|
||||||
preview,
|
})
|
||||||
})
|
const allProductsPromise = commerce.getAllProducts({
|
||||||
const allProductsPromise = commerce.getAllProducts({
|
variables: { first: 4 },
|
||||||
variables: { first: 4 },
|
config,
|
||||||
config,
|
preview,
|
||||||
preview,
|
})
|
||||||
})
|
|
||||||
|
|
||||||
const { pages } = await pagesPromise
|
const { pages } = await pagesPromise
|
||||||
const { categories } = await siteInfoPromise
|
const { categories } = await siteInfoPromise
|
||||||
const { product } = await productPromise
|
const { product } = await productPromise
|
||||||
const { products: relatedProducts } = await allProductsPromise
|
const { products: relatedProducts } = await allProductsPromise
|
||||||
|
|
||||||
if (!product) {
|
if (!product) {
|
||||||
return {
|
|
||||||
notFound: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
props: {
|
|
||||||
pages,
|
|
||||||
product,
|
|
||||||
relatedProducts,
|
|
||||||
categories,
|
|
||||||
},
|
|
||||||
revalidate: 200,
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error)
|
|
||||||
return {
|
return {
|
||||||
notFound: true,
|
notFound: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
props: {
|
||||||
|
pages,
|
||||||
|
product,
|
||||||
|
relatedProducts,
|
||||||
|
categories,
|
||||||
|
},
|
||||||
|
revalidate: 200,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStaticPaths({ locales }: GetStaticPathsContext) {
|
export async function getStaticPaths({ locales }: GetStaticPathsContext) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user