Update [...pages].tsx

This commit is contained in:
cond0r 2021-06-06 09:10:27 +03:00
parent 0e804d09f9
commit 5dd1a6e508

View File

@ -8,6 +8,7 @@ import { Text } from '@components/ui'
import { Layout } from '@components/common' import { Layout } from '@components/common'
import getSlug from '@lib/get-slug' import getSlug from '@lib/get-slug'
import { missingLocaleInPages } from '@lib/usage-warns' import { missingLocaleInPages } from '@lib/usage-warns'
import { useRouter } from 'next/router'
export async function getStaticProps({ export async function getStaticProps({
preview, preview,
@ -28,6 +29,7 @@ export async function getStaticProps({
config, config,
preview, preview,
})) }))
const page = data?.page const page = data?.page
if (!page) { if (!page) {
@ -58,16 +60,18 @@ export async function getStaticPaths({ locales }: GetStaticPathsContext) {
return { return {
paths, paths,
// Fallback shouldn't be enabled here or otherwise this route fallback: 'blocking',
// will catch every page, even 404s, and we don't want that
fallback: false,
} }
} }
export default function Pages({ export default function Pages({
page, page,
}: InferGetStaticPropsType<typeof getStaticProps>) { }: InferGetStaticPropsType<typeof getStaticProps>) {
return ( const router = useRouter()
return router.isFallback ? (
<h1>Loading...</h1> // TODO (BC) Add Skeleton Views
) : (
<div className="max-w-2xl mx-8 sm:mx-auto py-20"> <div className="max-w-2xl mx-8 sm:mx-auto py-20">
{page?.body && <Text html={page.body} />} {page?.body && <Text html={page.body} />}
</div> </div>