Add pretty URL redirects: /slug -> /blog/slug
This commit is contained in:
parent
77fb20abe4
commit
9af0acc294
1 changed files with 16 additions and 0 deletions
16
src/pages/[...id].astro
Normal file
16
src/pages/[...id].astro
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
---
|
||||
export const prerender = true;
|
||||
import { getCollection } from 'astro:content';
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection('blog');
|
||||
|
||||
return posts.map((post) => ({
|
||||
params: { id: post.id },
|
||||
props: { slug: post.id },
|
||||
}));
|
||||
}
|
||||
|
||||
const { slug } = Astro.props;
|
||||
return Astro.redirect(`/blog/${slug}`, 301);
|
||||
---
|
||||
Loading…
Add table
Add a link
Reference in a new issue