2019-08-06 22:26:01 +02:00
|
|
|
import React from 'react'
|
|
|
|
import Link from 'next/link'
|
2019-11-28 05:16:19 +01:00
|
|
|
import { useRouter } from 'next/router'
|
2019-08-06 22:26:01 +02:00
|
|
|
|
2019-09-24 10:50:04 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
2019-11-28 04:46:16 +01:00
|
|
|
export async function unstable_getStaticPaths() {
|
|
|
|
return [
|
|
|
|
'/blog/post-1',
|
|
|
|
{ params: { post: 'post-2' } },
|
|
|
|
'/blog/[post3]',
|
2019-12-12 10:45:45 +01:00
|
|
|
'/blog/post-4',
|
2019-11-28 04:46:16 +01:00
|
|
|
'/blog/post.1',
|
|
|
|
]
|
2019-09-24 10:50:04 +02:00
|
|
|
}
|
2019-08-06 22:26:01 +02:00
|
|
|
|
2019-09-24 10:50:04 +02:00
|
|
|
// eslint-disable-next-line camelcase
|
2019-11-11 04:24:53 +01:00
|
|
|
export async function unstable_getStaticProps({ params }) {
|
2019-09-24 10:50:04 +02:00
|
|
|
if (params.post === 'post-10') {
|
|
|
|
await new Promise(resolve => {
|
|
|
|
setTimeout(() => resolve(), 1000)
|
|
|
|
})
|
2019-08-06 22:26:01 +02:00
|
|
|
}
|
|
|
|
|
2019-10-17 17:52:13 +02:00
|
|
|
if (params.post === 'post-100') {
|
|
|
|
throw new Error('such broken..')
|
|
|
|
}
|
|
|
|
|
2019-09-24 10:50:04 +02:00
|
|
|
return {
|
|
|
|
props: {
|
2019-12-13 19:14:09 +01:00
|
|
|
params,
|
2019-09-24 10:50:04 +02:00
|
|
|
post: params.post,
|
2019-11-11 04:24:53 +01:00
|
|
|
time: (await import('perf_hooks')).performance.now(),
|
2019-09-24 10:50:04 +02:00
|
|
|
},
|
2019-11-11 04:24:53 +01:00
|
|
|
revalidate: 10,
|
2019-08-06 22:26:01 +02:00
|
|
|
}
|
|
|
|
}
|
2019-09-24 10:50:04 +02:00
|
|
|
|
2019-12-13 19:14:09 +01:00
|
|
|
export default ({ post, time, params }) => {
|
2019-09-24 10:50:04 +02:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<p>Post: {post}</p>
|
|
|
|
<span>time: {time}</span>
|
2019-12-13 19:14:09 +01:00
|
|
|
<div id="params">{JSON.stringify(params)}</div>
|
2019-11-28 05:16:19 +01:00
|
|
|
<div id="query">{JSON.stringify(useRouter().query)}</div>
|
2019-11-11 04:24:53 +01:00
|
|
|
<Link href="/">
|
|
|
|
<a id="home">to home</a>
|
2019-09-24 10:50:04 +02:00
|
|
|
</Link>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|