#Wildcard params
4 messages · Page 1 of 1 (latest)
Hi @umbral steeple. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, it is possible to create a page that serves dynamic content using wildcard parameters like [...path]. However, the way you handle these parameters depends on the mode you're using: Static Site Generation (SSG) or Server-Side Rendering (SSR).
In Static Site Generation (SSG) mode, you need to specify all possible paths using the getStaticPaths function. This is because Astro needs to know all the routes to generate at build time. Here's an example from the Astro documentation (https://docs.astro.build/en/core-concepts/routing#rest-parameters):
---export function getStaticPaths() { return [ {params: {path: 'one/two/three'}}, {params: {path: 'four'}}, {params: {path: undefined }} ]}
const { path } = Astro.params;---...
In Server-Side Rendering (SSR) mode, you don't need to use getStaticPaths. The page will be served to any matching route. Here's an example from the Astro documentation (https://docs.astro.build/en/core-concepts/routing#server-ssr-mode):
---const { resource, id } = Astro.params;---<h1>{resource}: {id}</h1>
This page will be served for any value of resource and id.
Please note that if you're using SSG mode and you don't specify all possible paths in getStaticPaths, Astro will throw an error as mentioned in this GitHub issue (https://github.com/withastro/astro/issues/9011).
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@umbral steeple kapa.ai is still learning and improving, please let us know how it did by reacting below