-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy path[id].js
45 lines (36 loc) · 954 Bytes
/
[id].js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Link from 'next/link'
const Show = ({ show, time }) => (
<div>
<p>This page uses getStaticProps() to pre-fetch a TV show.</p>
<p>Ids 1 and 2 are prerendered</p>
<hr />
<h1>Show #{show.id}</h1>
<p>{show.name}</p>
<p>Rendered at {time} </p>
<hr />
<Link href="/">
<a>Go back home</a>
</Link>
</div>
)
export async function getStaticPaths() {
// Set the paths we want to pre-render
const paths = [{ params: { id: '1' } }, { params: { id: '2' } }]
// We'll pre-render only these paths at build time.
return { paths, fallback: 'blocking' }
}
export async function getStaticProps({ params }) {
// The ID to render
const { id } = params
const res = await fetch(`https://api.tvmaze.com/shows/${id}`)
const data = await res.json()
const time = new Date().toLocaleTimeString()
return {
props: {
show: data,
time,
},
revalidate: 60,
}
}
export default Show