First Article&Routing
This commit is contained in:
28
src/pages/[...path].astro
Normal file
28
src/pages/[...path].astro
Normal file
@@ -0,0 +1,28 @@
|
||||
---
|
||||
import { resolveAllPaths, type ResolvedEntry } from '../lib/paths';
|
||||
import type { CollectionEntry } from 'astro:content';
|
||||
import ArticleLayout from '../layouts/ArticleLayout.astro';
|
||||
import PageLayout from '../layouts/PageLayout.astro';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const entries = await resolveAllPaths();
|
||||
return entries.map((entry) => ({
|
||||
params: { path: entry.path },
|
||||
props: entry,
|
||||
}));
|
||||
}
|
||||
const { type, entry } = Astro.props as ResolvedEntry;
|
||||
|
||||
const props = Astro.props as ResolvedEntry;
|
||||
---
|
||||
|
||||
{
|
||||
type === 'article' && (
|
||||
<ArticleLayout entry={props.entry as CollectionEntry<'articles'>} />
|
||||
)
|
||||
}
|
||||
{
|
||||
type === 'page' && (
|
||||
<PageLayout entry={props.entry as CollectionEntry<'pages'>} />
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user