fallback true; revalidate 30; show simple loader

This commit is contained in:
tmshv committed 2021-02-18 13:13:25 +03:00
1 parent bc07643b11
commit 7d10ea27f0
1 file changed
+16 -3
+16 -3
View File
@@ -15,6 +15,7 @@ import { Youtube } from '@/components/Youtube'
import { createPage, createPageUrls } from '@/remote/factory'
import { paramsToSlug } from '@/remote/lib'
import { PageGrid } from '@/components/PageGrid'
import { useRouter } from 'next/router'
async function getUrls() {
let urls = []
@@ -73,7 +74,17 @@ type Props = {
tokens: Token[]
}
const Index: NextPage<Props> = props => (
const Index: NextPage<Props> = props => {
const router = useRouter()
if (router.isFallback) {
return (
<div>
loading...
</div>
)
}
return (
<App
contentStyle={{
marginTop: 'var(--size-l)',
@@ -165,7 +176,8 @@ const Index: NextPage<Props> = props => (
</article>
</Page>
</App>
)
)
}
export const getStaticProps: GetStaticProps<any> = async ctx => {
const slug = paramsToSlug(ctx.params.slug)
@@ -190,6 +202,7 @@ export const getStaticProps: GetStaticProps<any> = async ctx => {
const tokens = page.tokens
return {
revalidate: 30,
props: {
tokens,
title: page.title,
@@ -205,7 +218,7 @@ export const getStaticPaths = async () => {
const urls = await getUrls()
return {
fallback: false,
fallback: true,
paths: urls
.map(path => {
const slug = tail(path.split('/'))