#Optional Route

6 messages · Page 1 of 1 (latest)

dim trout
#

how can i have an optional route in astro? in my pages directory, i have a blog directory, and in there i have a [slug].astro and a [category] dir which has an index.astro in it. index.astro has this frontmatter: ```astro
import { getCollection } from "astro:content"
import { categories } from "../../../categories"
export const getStaticPaths = async () => {
const posts = await getCollection("blog")

return categories.map(([category]) => ({
    params: { category },
    props: {
        filteredPosts: category
            ? posts.filter((post) => post.data.category == category)
            : posts
    }
}))

}```
I would like to make it so that /blog/ with no category in the path will still render the page, but have a category of undefined, is this possible? thanks.

#

to be clear i dont want both an index.astro in blog and an index.astro in blog/[category] if possible

lucid solar
dim trout
lucid solar
#

I recommend you try it, and if it does not work, post your example for further support. Examples you find might be more complex that what you need.