-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade starters to App Router #601
Comments
Thank you for providing this project, it is greatly appreciated. Currently, I am exploring the possibility of converting the starter to the app router using the latest library, specifically the one found at https://www.npmjs.com/package/next-drupal/v/0.0.0-pr.600.128d03bc. My objective at the moment is to gain a better understanding of how to migrate an existing project. So far everything is working fine, however, I believe I may be missing something important. Several functions utilize the How should I proceed with the conversion process? Would it be necessary to create a custom |
Another example of the Trying to convert to App Router, where we don't have anymore the context object, the only way I found to convert this one https://github.com/chapter-three/next-drupal-basic-starter/blob/main/pages/%5B...slug%5D.tsx, is: export default async function Page({ params }: any) {
const resource = await getPage(params);
return (
<Layout>
<Head>
<title>{resource.title}</title>
<meta name="description" content="A Next.js site powered by Drupal." />
</Head>
{resource.type === "node--page" && <NodeBasicPage node={resource} />}
{resource.type === "node--article" && <NodeArticle node={resource} />}
</Layout>
);
}
async function getPage(args: any) {
const path = await drupal.translatePathFromContext({ params: args });
if (!path) {
return {
notFound: true,
};
}
const type = path.jsonapi?.resourceName;
let params = {};
if (type === "node--article") {
params = {
include: "field_image,uid",
};
}
const resource = await drupal.getResourceFromContext<DrupalNode>(path, args, {
params,
});
// At this point, we know the path exists and it points to a resource.
// If we receive an error, it means something went wrong on Drupal.
// We throw an error to tell revalidation to skip this for now.
// Revalidation can try again on next request.
if (!resource) {
throw new Error(`Failed to fetch resource: ${path.jsonapi?.individual}`);
}
return resource;
} It mostly works, but yet, not sure if I'm (ab)using the API by manually crafting the context object. |
@JohnAlbin sorry for coming back on this. Can you help me to understand how the |
The Let's walk through the old How the old
|
@JohnAlbin, first of all, let me say thank you so much for your super detailed answers. Give me some time to connect all the dots, and hopefully, I can contribute back with some code too. |
@JohnAlbin I've created a diagram of the Pages Router flow. I would appreciate your feedback before I continue with the other flow. You can find it here: https://excalidraw.com/#room=f28794c0ac45452180bf,1OOdKSnoZByreHn6SkkZhA And here as an attachment, just remove .txt part of the extension. |
I've just added to the diagram even the new app router workflow, as you've described, it is the same link and attaached. |
Package
basic-starter
Describe the feature request
The current starters both use the Pages directory for routing.
Describe the solution you'd like
We should clone the
basic-starter
topages-starter
. And clonegraphql-starter
topages-graphql-starter
.And then we should upgrade the old starters to use the App Router.
The text was updated successfully, but these errors were encountered: