Hello everyone, I need help:
I'm coding astro whose job is to view post details. In the post list screen, I have an a tag to redirect with the slug extension (For example: /post/8). So in the file [slug].astro I have to declare getStaticPaths() but how can I predict the params, because the other slug is arbitrary and not fixed. How do I not have to define it first? Thanks and please help me
#help with dynamic route with [slug].astro
1 messages · Page 1 of 1 (latest)
getStaticPaths() generates pages for all known routes in "static" mode (i.e. SSG)
If you're routes are not known at build time, then you should use "hybrid" or "server" mode (i.e. SSR).
On the other hand, if you are trying to say that /post/8 should go to page 8 of the post list, then you are talking about pagination.
https://docs.astro.build/en/guides/routing/#pagination
thank you for sharing. My wish is that when I go to news/[slug]. That means in the [slug].astro file, I must know the slug or get the slug from the other list post page sent via herf -> to be able to declare it in getStaticPaths(). Once there are no more errors, I get the slug to call the api to get post details
getStaticPaths() does not "get" a slug, it's a static page generator. It generates all pages for all the slugs at build time. So when a visitor goes to /news/story1, getStaticPaths() has already generated that page.
You should consider starting from the beginning with the "Build your first Astro Blog" tutorial:
https://docs.astro.build/en/tutorial/0-introduction/
Or if you prefer watching videos, try:
https://www.youtube.com/watch?v=F2pw1C9eKXw
Docs
Learn the basics of Astro with a project-based tutorial. All the background knowledge you need to get started!
Join early access for my Astro course! https://learnastro.dev
In this course, we’ll build a custom Astro blog from scratch. Throughout the course, we’ll learn how to work with Astro components, import and process data, pass props, minify images, build an RSS feed, and more.
🔗 Key Links 🔗
- Github lesson code: https://github.com/coding-in-publ...