This repository demonstrates an issue with SvelteKit's typed routes when used with the reroute hook.
When using the reroute hook to create URL aliases (e.g., /ueber-uns
→ /about
), TypeScript's typed routes don't recognize the rerouted paths, causing type errors.
Install dependencies:
npm install
Run TypeScript check to see the errors:
npm run check
(Optional) Start the development server to test the reroute functionality:
npm run dev
Visit these URLs to see the reroute in action:
In src/routes/about/+page.svelte
:
let isGermanRoute = $derived(page.url.pathname === "/ueber-uns");
let isFrenchRoute = $derived(page.url.pathname === "/a-propos");
TypeScript produces these errors:
Error: This comparison appears to be unintentional because the types
'"/about" | "/" | `/${string}/about` | `/${string}/`' and '"/ueber-uns"' have no overlap.
Error: This comparison appears to be unintentional because the types
'"/about" | "/" | `/${string}/about` | `/${string}/`' and '"/a-propos"' have no overlap.
src/hooks.ts
- Contains the reroute configurationsrc/routes/about/+page.svelte
- Contains the code that triggers TypeScript errorsThere should be a way to inform the typed routes system about paths created through the reroute hook, or at least a recommended pattern to avoid these TypeScript errors while maintaining type safety. EOF < /dev/null