Skip to content

Commit ac76c9f

Browse files
authored
Fixes fallback for pages router (#40)
* Corrects cache kind for pages Ensures the cache `kind` property is correctly assigned as "PAGES" when dealing with non-app router pages. * Adds pages router example with static props * Bump packages
1 parent 9393ce2 commit ac76c9f

File tree

5 files changed

+155
-100
lines changed

5 files changed

+155
-100
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { GetStaticPaths, GetStaticProps } from "next";
2+
3+
interface Post {
4+
id: string;
5+
title: string;
6+
content: string;
7+
timestamp: string;
8+
}
9+
10+
interface PostPageProps {
11+
post: Post;
12+
}
13+
14+
export const getStaticPaths: GetStaticPaths = async () => {
15+
return {
16+
paths: [
17+
{ params: { id: "1" } },
18+
{ params: { id: "2" } },
19+
{ params: { id: "3" } },
20+
],
21+
fallback: false,
22+
};
23+
};
24+
25+
export const getStaticProps: GetStaticProps<PostPageProps> = async ({
26+
params,
27+
}) => {
28+
const post: Post = {
29+
id: params?.id as string,
30+
title: `Post ${params?.id}`,
31+
content: `This is the content for post ${params?.id}`,
32+
timestamp: new Date().toISOString(),
33+
};
34+
35+
return {
36+
props: {
37+
post,
38+
},
39+
revalidate: 60,
40+
};
41+
};
42+
43+
export default function Post({ post }: PostPageProps) {
44+
return (
45+
<div>
46+
<h1>{post.title}</h1>
47+
<p>{post.content}</p>
48+
<p>
49+
<small>Generated at: {post.timestamp}</small>
50+
</p>
51+
</div>
52+
);
53+
}

0 commit comments

Comments
 (0)