Skip to content

Instantly share code, notes, and snippets.

@eladroz
Created April 4, 2022 08:02
Show Gist options
  • Save eladroz/eab774aafce43dc20a8e20a38a514101 to your computer and use it in GitHub Desktop.
Save eladroz/eab774aafce43dc20a8e20a38a514101 to your computer and use it in GitHub Desktop.
SvelteKit: invalidate page on content update
<script context="module">
export async function load({ url }) {
return {
props: {
currentUrl: url.pathname,
},
};
}
</script>
<script>
import { invalidate } from "$app/navigation";
export let currentUrl;
if (import.meta.hot) {
import.meta.hot.on("content-update", () => {
invalidate(`${currentUrl}.json`);
console.log("Content update - invalidating current page");
});
}
</script>
<slot />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment