You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: www/content/docs/pages.mdx
+89-1Lines changed: 89 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -214,4 +214,92 @@ See the [fetching JSON:API resources](/docs/fetching-resources) section for more
214
214
215
215
## Pages Router
216
216
217
-
TODO - Port some examples from the previous docs.
217
+
When using the Pages Router, you will use the `getStaticProps` and `getServerSideProps` methods to fetch data for your pages.
218
+
219
+
### Basic Example
220
+
221
+
Here's an example which uses `getResource` to fetch a `page` node by ID:
222
+
223
+
```tsx
224
+
const node =awaitdrupal.getResource(
225
+
"node--page",
226
+
"07464e9f-9221-4a4f-b7f2-01389408e6c8"
227
+
)
228
+
```
229
+
230
+
A full page would look like this:
231
+
232
+
```tsx title=pages/about.tsx
233
+
// node will be populated at build time by getStaticProps
234
+
exportdefaultfunction AboutPage({ node }) {
235
+
return (
236
+
<article>
237
+
<h1>{node.title}</h1>
238
+
// ...
239
+
</article>
240
+
)
241
+
}
242
+
243
+
exportasyncfunction getStaticProps() {
244
+
// Fetch the node from Drupal.
245
+
const node =awaitdrupal.getResource(
246
+
"node--page",
247
+
"07464e9f-9221-4a4f-b7f2-01389408e6c8"
248
+
)
249
+
250
+
// Pass the node as props to the AboutPage.
251
+
return {
252
+
props: {
253
+
node,
254
+
},
255
+
}
256
+
}
257
+
```
258
+
259
+
---
260
+
261
+
## Dynamic pages
262
+
263
+
You can use Next.js [dynamic route](https://nextjs.org/docs/basic-features/pages#pages-with-dynamic-routes) to build static pages for Drupal entity types.
264
+
265
+
Start by creating a page at `/pages/[...slug].tsx`, where `[...slug]` maps to the **path alias** for an entity type (or content type) in Drupal.
266
+
267
+
This means `/pages/[...slug].tsx` will handle all pages with the following aliases: `/about`, `/team`, `/another/path` ...etc.
268
+
269
+
To build static pages, there are two functions we need to implement:
270
+
271
+
1.`getStaticPaths`: to tell Next.js all the routes that we want to be rendered.
Copy file name to clipboardExpand all lines: www/content/tutorials/on-demand-revalidation/index.mdx
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,3 +8,7 @@ group: On-demand Revalidation
8
8
[On-demand Revalidation](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#on-demand-revalidation) makes it easy to update your Next.js site when content on Drupal is created, updated or deleted.
9
9
10
10
Starting with `v1.6.0`, Next.js for Drupal supports On-demand Revalidation configurable per entity types.
11
+
12
+
TODO - in v2, Next.js for Drupal supports...
13
+
TODO - maybe this section should just be renamed to validation?
14
+
TODO - maybe move revalidation examples from Building Pages to this section...
0 commit comments