Static pages
- Assuming you need to add static data for a collection called
tests
Create the collection folder
mkdir pages/tests
touch pages/tests/[slug].js
- This would create links for the dynamic pages in the format ->
/tests/slug
Creating paths
- We use the graphcms data to create static paths here
- But can be used for anything
import { GraphQLClient } from "graphql-request";
const graphcms = new GraphQLClient(process.env.GRAPHCMS_URL);
export async function getStaticPaths() {
const { tests } = await graphcms.request(`{
tests {
slug
id
title
}
}`);
return {
paths: tests.map(({ slug }) => ({ params: { slug } })),
fallback: false,
};
}