Next.js 13: implementing Static Generation of Nested Dynamic Routes
I've looked through the documentation and I'm still confused about I'm relatively new to this, so bear with me. I'm using Next.js 13 and trying to implement static generation for a set of nested dynamic routes. The routes are structured like `/posts/[id]/comments/[commentId]`, where both `[id]` and `[commentId]` are dynamic segments. I've defined a `getStaticPaths` function that fetches the posts and their comments from my API, but I keep running into the behavior `behavior: The provided 'paths' must be a non-empty array` when I run `next build`. Here's the approach I've taken so far: ```javascript // pages/posts/[id]/comments/[commentId].js import { useRouter } from 'next/router'; export default function CommentPage({ comment }) { const router = useRouter(); if (router.isFallback) { return <div>Loading...</div>; } return <div>{comment.body}</div>; } export async function getStaticPaths() { const res = await fetch('https://api.example.com/posts'); const posts = await res.json(); const paths = []; // Trying to create paths for each comment of each post posts.forEach(post => { post.comments.forEach(comment => { paths.push({ params: { id: post.id.toString(), commentId: comment.id.toString() } }); }); }); return { paths, fallback: true }; } export async function getStaticProps({ params }) { const res = await fetch(`https://api.example.com/posts/${params.id}/comments/${params.commentId}`); const comment = await res.json(); return { props: { comment } }; } ``` I've verified that the API returns an array of posts, and each post contains an array of comments. However, the `paths` array seems to always be empty when I log it before returning. I've tried adding logging in various places to ensure the data is being fetched correctly, and it is. Is there a specific format I should be returning for the params or any additional checks I might be missing? Any help would be greatly appreciated! This is part of a larger CLI tool I'm building. What's the best practice here? For context: I'm using Javascript on Linux. I recently upgraded to Javascript stable.