#Routing

2 messages · Page 1 of 1 (latest)

quiet sandalBOT
#

Hi @remote dagger. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Yes, you can use the same pages for another route in Astro. However, it's important to note that Astro uses file-based routing, which means your build URLs are generated based on the file layout of your project src/pages/ directory. When you add a file to the src/pages/ directory, a new route is automatically created for you.

If you want to use the same page for another route, you can create a dynamic route. An Astro page file can specify dynamic route parameters in its filename to generate multiple, matching pages. For example, src/pages/authors/[author].astro generates a bio page for every author on your blog. author becomes a parameter that you can access from inside the page.

In a Github issue (https://github.com/withastro/astro/issues/1039), a user suggested a workaround for using the same pages for different routes. The idea is to put the pages in the components folder and generate the routes in the pages folder. Each page only contains an import statement for the corresponding component from the components folder.

Here's an example of what the code in each page might look like:

---
import SomePage from "../components/pages/some-page.astro";
---

However, please note that this approach might not be suitable for all use cases and it's always a good idea to structure your project in a way that best fits your needs.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: