sveltekit-reroute-typed-route-repro Svelte Themes

Sveltekit Reroute Typed Route Repro

Reproduction repository demonstrating TypeScript errors with SvelteKit's typed routes and reroute hook

SvelteKit Reroute + Typed Routes Issue Reproduction

This repository demonstrates an issue with SvelteKit's typed routes when used with the reroute hook.

Issue

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.

Steps to Reproduce

  1. Install dependencies:

    npm install
    
  2. Run TypeScript check to see the errors:

    npm run check
    
  3. (Optional) Start the development server to test the reroute functionality:

    npm run dev
    

    Visit these URLs to see the reroute in action:

The Problem

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.

Files

  • src/hooks.ts - Contains the reroute configuration
  • src/routes/about/+page.svelte - Contains the code that triggers TypeScript errors

Expected Behavior

There 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

Top categories

Loading Svelte Themes