I ran into an issue with the new nextjs app router
where i wanted to use SSG pages for stapi blog but was getting this error when building
app/blog/[slug]/page.tsx
Type error: Page "app/blog/[slug]/page.tsx" does not match the required types of a Next.js Page.
"getStaticPaths" is not a valid Page export field.
for
import { BlogArticlePreview } from "@/components/landingPages/BlogArticles";
import { getBlog, getBlogs } from "@/services/strapi/modules/blog";
import { BlogPage } from "./BlogPage";
const fetchBlog = async (slug: string) => {
try {
return await getBlog(slug);
} catch (error) {
return null;
}
};
export const getStaticPaths = async () => {
const data = await getBlogs();
const paths = (data as any).data.map((item: any) => {
return {
params: { slug: item.attributes.slug },
};
});
return {
paths,
fallback: true,
};
};
export default async function Page({ params }: any) {
const blog = ((await fetchBlog(params.slug)) as any)
?.attributes as unknown as BlogArticlePreview;
return <BlogPage {...blog} />;
}
3
Answers
Found a way to do so
Method:
Example:
Try
You are using the
App Router
which replaced thegetStaticPaths
withgenerateStaticParams
. Check the migration guide.