Created
April 4, 2022 08:02
-
-
Save eladroz/eab774aafce43dc20a8e20a38a514101 to your computer and use it in GitHub Desktop.
SvelteKit: invalidate page on content update
This file contains hidden or 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 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