Hash router for Sveltekit projects
This is an extension package for webJose's Svelte Router, and enables the use of the router in hash mode in Sveltekit projects.
Sveltekit has an excellent file-based router. You should always stick to the built-in router for routing your application. However, as with every other router in existence, you can only do path routing or hash routing, but not both.
webJose's Svelte Router router was born to break this barrier: This SPA router can do path and hash routing simultaneously. However, this is a router for SPA's and PWA's that render on the client. It was not designed for SSR scenarios. After all, Sveltekit has routing capabilities included.
But what if you wanted to do hash routing on top of Sveltekit's path routing? You can today, with this router extension.
npm install @svelte-router/kit # This also installs the @svelte-router/core main package
+layout.svelte component:<script lang="ts">
import { init } from "@svelte-router/kit";
init(/* options */);
</script>
@svelte-router/core.Fallback component. Use this package's KitFallback component for
fallback content to avoid flashes of unwanted content when rendering on the server.⚡ Attention!
There might be a bug in Svelte or Sveltekit. Situation: Just importing
initfrom@svelte-router/kittriggers errorrune_outside_svelteon thetrace.svelte.jsfile in the@svelte-router/corepackage. To overcome this, just add{ ssr: { noExternal: ["@svelte-router/core"] }}to Vite's configuration.If this becomes unneeded, this warning will be removed; if this is just the reality of things, this warning will become one more step in the quickstart.
Generally speaking, you need to understand the core router, so have handy its online documentation.