#Can Astro manage more than one dynamic route?

20 messages · Page 1 of 1 (latest)

jolly trench
#

Can Astro manage more than one dynamic route?

#

Basically the progetti page shows me the metodo page content

wind pilot
#

If both routes are on-demand rendered, no

jolly trench
#

Yes both ssr

wind pilot
#

They'd be conflicting otherwise

wind pilot
#

You could work that around by rendering different component pages depending on the query params

jolly trench
#

I'm using a cms, i need to have the pages in ssr

#

this is the metodo page for example

#

i'm actually stuck now that i think about it

#

if i can't manage multiple dynamic routes then i have to rethink the whole project logic

#

first project in astro btw

wind pilot
#

You could extract those pages as components, use a common route for both pages, say [locale]/[metodo_or_progetti].astro, and render them conditionally using Astro.params.metodo_or_progetti

#

The common page would look something like this

---
import ProgettiPage from "../components/pages/Progetti.astro"
import MetodoPage from "../components/pages/Metodo.astro"

// logic to match which page to render
const isProgetti = progettiMap.has(Astro.params.metodo_or_progetti)

// redirects should be on the top level page
---
{
  isProgetti ? <ProgettiPage /> : <MetodoPage />
}
jolly trench
#

ok but its hard to manage this... i have 6 dynamic routs, 2 of which have subpages. [slug] for example

#

it's a clever solution but i wonder how to manage those multiple scenarios, and subpages too

wind pilot
#

I just looked at the code again and it looks like you're not using Astro.params

#

Are you using it locally?

#

If not then you probably don't need to use dynamic routes in the first place

Edit: Seems like you do actually, as you're passing Astro to useI18n.
Problem is that Astro can't know which route to render in this case as both routes have the same matchers. Another way around this would be to prefix your dynamic routes when they're colliding, so p-[progetti]/index.astro and m-[metodo]/index.astro for example so the routes don't collide