Merge pull request #69 from tmshv/upd/next-fallback-revalidate

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