I just started using Strapi for the first time, and I use Astro for the front-end. I created a ./src/pages/[slug].astro file, and it works for pages with a slug. But when I browser to the Astro instance without using a slug (/
), then I get a 404.
This topic has been created from a Discord post (1272309531652784149) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord
This is my slug file:
---
import fetchApi from '../lib/strapi';
import type Page from '../interfaces/page';
import Layout from '../layouts/Layout.astro';
export async function getStaticPaths() {
const pages = await fetchApi<Page[]>({
endpoint: 'pages',
wrappedByKey: 'data',
});
return pages.map((page) => ({
params: { slug: page.attributes.slug },
props: page,
}));
}
type Props = Page;
const page = Astro.props;
---
<Layout title={page.attributes.title}>
<section>
<div class='prose prose-base mx-auto'>
<h1>{page.attributes.title}</h1>
</div>
</section>
</Layout>
I believe I can create an index.astro file where I fetch a specific page, but I don’t know if that’s the best approach.