-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreact-router.config.ts
More file actions
29 lines (24 loc) · 868 Bytes
/
react-router.config.ts
File metadata and controls
29 lines (24 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import type { Config } from "@react-router/dev/config";
import { client } from "tina/__generated__/client";
export default {
// Config options...
// Server-side render by default, to enable SPA mode set this to `false`
ssr: false,
async prerender() {
// Start with the static routes
const routes = ["/", "/posts"];
// Fetch all post slugs from Tina CMS
try {
const postsResponse = await client.queries.postConnection();
const postSlugs =
postsResponse.data.postConnection.edges
?.filter((edge) => edge?.node)
?.map((post) => `/posts/${post?.node?._sys.filename}`) ?? [];
// Add all post routes to the prerender list
routes.push(...postSlugs);
} catch (error) {
console.error("Error fetching posts for prerendering:", error);
}
return routes;
},
} satisfies Config;