diff --git a/examples/api-routes/components/Person.js b/examples/api-routes/components/Person.js
index 16c2bf63a523c..d43584b1668bc 100644
--- a/examples/api-routes/components/Person.js
+++ b/examples/api-routes/components/Person.js
@@ -2,7 +2,7 @@ import Link from 'next/link'
export default ({ person }) => (
-
+
{person.name}
diff --git a/examples/api-routes/package.json b/examples/api-routes/package.json
index 5eeb8a1552fb2..f74abdd7e0fca 100644
--- a/examples/api-routes/package.json
+++ b/examples/api-routes/package.json
@@ -7,8 +7,8 @@
"start": "next start"
},
"dependencies": {
- "isomorphic-unfetch": "3.0.0",
"next": "latest",
+ "node-fetch": "2.6.0",
"react": "^16.8.6",
"react-dom": "^16.8.6"
},
diff --git a/examples/api-routes/pages/index.js b/examples/api-routes/pages/index.js
index 4f1b5c97d411e..0197601de6843 100644
--- a/examples/api-routes/pages/index.js
+++ b/examples/api-routes/pages/index.js
@@ -1,5 +1,5 @@
import Person from '../components/Person'
-import fetch from 'isomorphic-unfetch'
+import fetch from 'node-fetch'
const Index = ({ people }) => (
@@ -9,11 +9,11 @@ const Index = ({ people }) => (
)
-Index.getInitialProps = async () => {
+export async function getStaticProps() {
const response = await fetch('http://localhost:3000/api/people')
const people = await response.json()
- return { people }
+ return { props: { people } }
}
export default Index
diff --git a/examples/api-routes/pages/person.js b/examples/api-routes/pages/person/[id].js
similarity index 63%
rename from examples/api-routes/pages/person.js
rename to examples/api-routes/pages/person/[id].js
index ec15c7a3786c0..5c98e8e845172 100644
--- a/examples/api-routes/pages/person.js
+++ b/examples/api-routes/pages/person/[id].js
@@ -1,4 +1,4 @@
-import fetch from 'isomorphic-unfetch'
+import fetch from 'node-fetch'
const Person = ({ data, status }) =>
status === 200 ? (
@@ -30,11 +30,29 @@ const Person = ({ data, status }) =>
{data.message}
)
-Person.getInitialProps = async ({ query }) => {
- const response = await fetch(`http://localhost:3000/api/people/${query.id}`)
+export async function getStaticPaths() {
+ const response = await fetch('http://localhost:3000/api/people')
+ const data = await response.json()
+
+ const paths = data.map(person => ({
+ params: {
+ id: person.id,
+ },
+ }))
+ return { paths, fallback: false }
+}
+
+export async function getStaticProps({ params }) {
+ const response = await fetch(`http://localhost:3000/api/people/${params.id}`)
const data = await response.json()
- return { data, status: response.status }
+
+ return {
+ props: {
+ data,
+ status: response.status,
+ },
+ }
}
export default Person