Last active
March 11, 2020 01:35
-
-
Save natxoski/37f19fc03c7a966075de6946ccd7893d to your computer and use it in GitHub Desktop.
Svelte Components Dynamic Import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
export let templatePath; | |
let module; | |
if (!!templatePath && templatePath != "") { | |
import(templatePath) | |
.then(m => { | |
module = m.default; | |
return; | |
}) | |
.catch(err => console.log(err)); | |
} | |
</script> | |
{#if !!module} | |
<svelte:component this={module} {...$$props}/> | |
{:else } | |
Error loading your component. Check your path on templatePath prop. | |
{/if} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment