You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<script>
import { preloadData } from'$app/navigation';importModalfrom"$lib/Modal.svelte"importPhotoPagefrom'./[id]/+page.svelte'; // Static import required, could also be `await import(...)`constmodalData=awaitpreloadData(href); // I can get the data from href, but not the related `+page.svelte` component
</script>
{#ifmodalOpened}
<Modal>
<PhotoPagedata={modalData} />
</Modal>
{/if}
While preloadData() allows us to dynamically fetch route data, there's no equivalent for loading the page component itself. This becomes problematic when handling multiple shallow routes, as each +page.svelte component must be imported statically at build time.
Describe the proposed solution
I'd like to dynamically resolve page components at runtime, similar to how we fetch data:
But i do wonder how your page component looks like if you can reuse it within the modal. I typically use a specific component for such use cases that i use on the modal and the actual page.
Yes I know that I can use a dynamic import but I still need to reference the ./[id]/+page.svelte path in my source code. In my case I have many links to different routes that I open in a modal, so instead I would like the SvelteKit router to resolve these components from a href.
Describe the problem
When implementing shallow routing with modals in SvelteKit, we currently need to statically import page components:
https://svelte.dev/docs/kit/shallow-routing#Loading-data-for-a-route
While
preloadData()
allows us to dynamically fetch route data, there's no equivalent for loading the page component itself. This becomes problematic when handling multiple shallow routes, as each+page.svelte
component must be imported statically at build time.Describe the proposed solution
I'd like to dynamically resolve page components at runtime, similar to how we fetch data:
This would simplify shallow routing implementations, especially when dealing with multiple potential routes that could be opened in a modal.
Alternatives considered
The signature of
preloadCode
could be changed to return the+page.svelte
componentImportance
nice to have
Additional Information
No response
The text was updated successfully, but these errors were encountered: