diff --git a/examples/example-router-migration/README.md b/examples/example-router-migration/README.md index c694ee20..6b809ed0 100644 --- a/examples/example-router-migration/README.md +++ b/examples/example-router-migration/README.md @@ -37,6 +37,7 @@ Over time, you will be moving all the files from `/pages` to `/app`. However, th 2. Delete the last files in your `/pages` directory: - `/pages/api/exit-preview.ts` - `/pages/api/preview.ts` +3. Update your `lib/drupal.ts` file and switch from the `DrupalClient` class (with dual Pages/App Router support) to the new, leaner `NextDrupal` class (with only App Router support). ## License diff --git a/examples/example-router-migration/app/[...slug]/page.tsx b/examples/example-router-migration/app/[...slug]/page.tsx index 45326787..4e61889c 100644 --- a/examples/example-router-migration/app/[...slug]/page.tsx +++ b/examples/example-router-migration/app/[...slug]/page.tsx @@ -76,15 +76,29 @@ export async function generateMetadata( const RESOURCE_TYPES = ["node--page", "node--article"] export async function generateStaticParams(): Promise { - // TODO: Replace getStaticPathsFromContext() usage since there is no context. - const paths = await drupal.getStaticPathsFromContext(RESOURCE_TYPES, {}) - // console.log( - // "generateStaticParams", - // paths.map(({ params }) => params) - // ) - return paths.map((path: string | { params: NodePageParams }) => - typeof path === "string" ? { slug: [] } : path?.params + const resources = await drupal.getResourceCollectionPathSegments( + RESOURCE_TYPES, + { + // The pathPrefix will be removed from the returned path segments array. + // pathPrefix: "/blog", + // The list of locales to return. + // locales: ["en", "es"], + // The default locale. + // defaultLocale: "en", + } ) + + return resources.map((resource) => { + // resources is an array containing objects like: { + // path: "/blog/some-category/a-blog-post", + // type: "node--article", + // locale: "en", // or `undefined` if no `locales` requested. + // segments: ["blog", "some-category", "a-blog-post"], + // } + return { + slug: resource.segments, + } + }) } export default async function NodePage({ diff --git a/examples/example-router-migration/lib/drupal.ts b/examples/example-router-migration/lib/drupal.ts index e390f347..1b13292e 100644 --- a/examples/example-router-migration/lib/drupal.ts +++ b/examples/example-router-migration/lib/drupal.ts @@ -1,4 +1,7 @@ -import { DrupalClient } from "next-drupal" +import { + DrupalClient, + // NextDrupal +} from "next-drupal" const baseUrl: string = process.env.NEXT_PUBLIC_DRUPAL_BASE_URL || "" const clientId = process.env.DRUPAL_CLIENT_ID || "" @@ -11,3 +14,13 @@ export const drupal = new DrupalClient(baseUrl, { }, debug: true, }) + +// TODO: Once you have migrated fully to App Router, switch to the leaner +// NextDrupal class (which contains none of the Pages Router-specific methods.) +// export const drupal = new NextDrupal(baseUrl, { +// auth: { +// clientId, +// clientSecret, +// }, +// debug: true, +// })