🐛 BUG: getStaticPaths() doesn't allow to create a top level root
What version of astro are you using?
1.0.0-beta.73
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Linux
Describe the Bug
getStaticPaths() should allow to create a top level root page (e.g. a Frontpage derived from a headless CMS along with all other content).
So if I have /pages/[...slug].astro, the empty slug ("") doesn't work and calling / results in a 404.
export function getStaticPaths() {
return [
{ params: { slug: "" }, props: { title: "Frontpage" } },
{ params: { slug: "a" }, props: { title: "Page a" } },
{ params: { slug: "a/b" }, props: { title: "Subpage b" } },
];
}
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-lspe41?file=src/pages/[...slug].astro
Participation
- [ ] I am willing to submit a pull request for this issue.
Thanks for opening an issue! I know we discussed this on Discord. Seems like a perfectly valid use case—this would be nice to support.
I know @crutchcorn had a similar request recently.
I've checked again... the "root" slug must be undefined instead of an empty string. The following code works as expected in Astro 1.0.1... maybe it would have worked in earlier versions, too.
Maybe we should document this case, so other people won't get distracted, too.
---
export async function getStaticPaths() {
const pages = [undefined, "page", "page/subpage"];
return pages.map((slug) => {
return {
params: { slug }, props: { title: `slug: ${slug}` }
};
});
}
const { title } = Astro.props
---
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>Astro</title>
</head>
<body>
{title}
</body>
</html>