#Wrong template being selected.

1 messages · Page 1 of 1 (latest)

tame knollBOT
#

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

#

Astro uses a routing system that matches URLs to file paths in your project. When you have multiple dynamic routes in the same directory, Astro might not always select the correct template due to the way it prioritizes routes.

From the information provided in the extracts, it seems that Astro prioritizes static routes over dynamic ones, and named path parameters over catch-all path parameters. This is documented in Astro's routing guide here (https://docs.astro.build/core-concepts/routing/#dynamic-routes).

However, there are some known issues with dynamic routing in Astro. For instance, there's a reported bug where having 2+ dynamic routes in the same folder causes only one to work. A workaround suggested in the Github issue (https://github.com/withastro/astro/issues/3621) is to move the logic for those dynamic routes into separate components, and then have one dynamic route that defers to the right component based on some condition.

Here's an example of how you might do this:

---
import Page from '../components/Page.astro';
import Post from '../components/Post.astro';
---
{ Astro.props.type === 'post' ? <Post {...Astro.props} /> : <Page {...Astro.props} /> }

In this example, the type of the page is used to determine which component to render. You could adapt this to your own needs by using a different condition.

If this doesn't solve your issue, it might be a bug in Astro. In that case, you could report it on the Astro Github issues page (https://github.com/withastro/astro/issues).

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