Closed oliverlietz closed 1 year ago
You have to use undefined
as the slug to generate an index route. See this example: https://stackblitz.com/edit/github-z4igp1-mwgqtc?file=src%2Fcontent%2Fpages%2Findex.md
Oops, this is a working version: https://stackblitz.com/edit/github-z4igp1-s5vuq7?file=src%2Fcontent%2Fpages%2Findex.md
Working:
---
import {getCollection} from 'astro:content';
export async function getStaticPaths() {
const pages = await getCollection('pages');
return pages.map(page => ({
params: {slug: page.slug || undefined}, props: {page},
}));
}
const {page} = Astro.props;
const {Content} = await page.render();
---
@matthewp, Is it documented already somewhere?
What version of
astro
are you using?2.4.2
Are you using an SSR adapter? If so, which one?
none
What package manager are you using?
npm
What operating system are you using?
Mac
What browser are you using?
any
Describe the Bug
It's not possible to serve the root page (e.g. index.md) from a content collection:
Setting slug in front matter to '/' (slash) or '' (empty string) does not work.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-z4igp1-mwgqtc
Participation