-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
index page not found for site root (/) when using content collection #7038
Comments
You have to use |
Oops, this is a working version: https://stackblitz.com/edit/github-z4igp1-s5vuq7?file=src%2Fcontent%2Fpages%2Findex.md |
Working:
@matthewp, Is it documented already somewhere? |
@oliverlietz I also wanted to use the same Astro template for both (a static index route and dynamic content routes). The key to solve this is ensuring that the paths returned by Here is my working example: src/pages/course/[...slug].astro ---
import { getCollection } from 'astro:content';
import Sidebar from '~/components/course/Sidebar.astro';
import PageLayoutText from '~/layouts/PageLayoutText.astro';
export async function getStaticPaths() {
const chapters = await getCollection('course');
const paths = [
{
params: { slug: '/' },
props: { chapter: chapters[0] },
},
];
paths.push(
...chapters.map((chapter) => ({
params: { slug: chapter.slug },
props: { chapter },
}))
);
return paths;
}
const { chapter } = Astro.props;
const { Content, headings } = await chapter.render();
---
<PageLayoutText>
<div class="flex">
<aside class="w-1/4 border">
<Sidebar toc={headings} />
</aside>
<main class="w-3/4 border">
<Content />
</main>
</div>
</PageLayoutText> Best, |
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
The text was updated successfully, but these errors were encountered: