#Load Astro Templates via URL (SSR)

4 messages · Page 1 of 1 (latest)

full thunder
#

Hi,

I want to load .astro templates dynamically via URL. (SSR mode is enabled).

For example:
localhost:3000/components/slider

The slider from src/components/Slider.astro, should then appear in the content. With set:html I can do this with .html files from the public folder, but not with .astro files. Does anyone have an idea, how to achieve this?

I want to build a dynamic playground for a web-components design system, to preview how the component is displayed in each project. (domain.tld/[project]/[web-component-name])

Unfortunately I didn't find anything suitable in the documentation and the parts that looked promising, only import the path and not the file contents. Something like this would be nice:

`// not working:

const { filename } = Astro.params;
const Component = await import(../components/${filename}.astro);`

<Component />`

All examples I've found so far, are only related to JSON data or static .html or .md files.
I think this one comes closest, but unfortunately it lacks some context for implementation for me:
#framework message

#

@young pendant is there any repo to see this in action?

full thunder
#

Why do I always find a solution by myself, after I posted my question somewhere...? 😂
https://dpaste.org/dnMXe

But what does the .default do here? I had already tried something similar, only without the .default - so it didn't work.