Consider an Astro page at src/pages/blog/[slug].astro that uses the dynamic parameter slug. What will this component render if the URL is /blog/hello-world?
---
const { slug } = Astro.params;
---
<html>
<body>
<h1>Blog Post: {slug}</h1>
</body>
</html>Remember that Astro.params contains the dynamic parts of the URL.
The dynamic parameter slug is extracted from the URL and used in the template. For /blog/hello-world, slug is hello-world.
You want to create a dynamic route in Astro to handle user profiles by username. Which filename is correct?
Astro uses square brackets to define dynamic route parameters.
Astro dynamic routes use square brackets around the parameter name in the filename, like [username].astro.
Given this code in src/pages/product/[id].astro, why does the page show Product ID: undefined?
---
const id = Astro.params.id;
---
<html>
<body>
<h2>Product ID: {id}</h2>
</body>
</html>Check the URL you are visiting and if it matches the dynamic route pattern.
If the URL does not include the dynamic segment (like /product), then Astro.params.id will be undefined, causing the output to show 'undefined'.
Given a file src/pages/shop/[category]/[item].astro with this code:
---
const { category, item } = Astro.params;
---
Category: {category}
Item: {item}
What will be rendered when visiting /shop/electronics/laptop?
Astro extracts all dynamic segments from the URL into Astro.params.
Both category and item are dynamic parameters and will be set from the URL segments.
You have these two files in src/pages:
[user].astro[user]/[post].astro
What will happen when you visit /alice and /alice/123?
Think about how nested dynamic routes match URLs in Astro.
Astro matches the URL to the most specific route file. /alice matches [user].astro, and /alice/123 matches the nested [user]/[post].astro.
