-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy path[id].js
55 lines (43 loc) · 1.19 KB
/
[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
46
47
48
49
50
51
52
53
54
55
import { useRouter } from 'next/router'
import Link from 'next/link'
const Show = ({ show }) => {
const router = useRouter()
// This is never shown on Netlify. We just need it for NextJS to be happy,
// because NextJS will render a fallback HTML page.
if (router.isFallback) {
return <div>Loading...</div>
}
return (
<div>
<p>
Check the network panel for the header <code>x-middleware-date</code> to ensure that it is running
</p>
<hr />
<h1>Show #{show.id}</h1>
<p>{show.name}</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: '3' } }, { params: { id: '4' } }]
// We'll pre-render these paths at build time.
// { fallback: true } means other routes will be rendered at runtime.
return { paths, fallback: true }
}
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()
return {
props: {
show: data,
},
}
}
export default Show