0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-24 23:21:57 -05:00
astro/packages/router/Outlet.astro
2022-03-27 09:30:12 -05:00

25 lines
598 B
Text

---
const { default: route, id } = Astro.props;
function getRoutePath(...args) {
return args.map(arg => arg.replace(/^\/|\/$/g, '')).join('/');
}
let Child = Fragment;
if (route) {
try {
const { default: Component } = await import(`/src/pages/routes/${getRoutePath(id, route)}.astro`);
if (Component) {
Child = Component;
}
} catch (e) {}
try {
const { default: Component } = await import(`/src/pages/routes/${getRoutePath(id, route)}/index.astro`);
if (Component) {
Child = Component;
}
} catch (e) {}
}
---
<router-outlet id={id} route={route}><Child /></router-outlet>