Conditionally render an Astro component based on page type query

Conditionally render an Astro component based on page type query


0

I am using Astro, GraphQL (Apollo Client), Typescript and React.

In my dynamic route: [...slug].astro file I need to conditionally render a certain Astro component.

I managed to that with:

 {data.page.type === 'PageOneType' && <PageOne />}
 {data.page.type === 'PageTwoType' && <PageTwo />}

Can I somehow make this more dynamic, so I don’t have to add it static like above in case there are more page types in the feature?

Or do I need to pull in React for this?


Load 1 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *