How to create a child page with getStaticPaths():
1. What is getStaticPaths() ?
getStaticPaths() function2. What to write in getStaticPaths() ?
export async function getStaticPaths() {
return [{
params: { child: 2 }
}];
}3. Create an empty Astro project .
npm create astro@latest4. Add child page .
project/src/pages[child].astro, should be at the same level as index.astro---
export function getStaticPaths() {
return [{
params: { child: 1 },
}];
}
const { child } = Astro.params;
---
<p> child page {child}</p>
{params: { child: 1 }} will create a single page similar to https://somesite.com/1{params: { child: 2 }} will create 2 pages https://somesite.com/1 and https://somesite.com/2Is that easy.
