# Migration Guide: Migrating to @keenmate/svelte-spa-router This guide helps you migrate from other routers to @keenmate/svelte-spa-router (Svelte 5 with runes). ## Prerequisites - Upgrade to Svelte 5 - Understand [Svelte 5 runes](https://svelte.dev/docs/svelte/what-are-runes) ## Step 1: Update Dependencies ```bash npm uninstall svelte-spa-router npm install @keenmate/svelte-spa-router svelte@^5.0.0 ``` ## Step 2: Update Imports Change all imports from `svelte-spa-router` to `@keenmate/svelte-spa-router`: **Before:** ```js import Router from 'svelte-spa-router' import {link, location, querystring, params} from 'svelte-spa-router' import {wrap} from 'svelte-spa-router/wrap' import active from 'svelte-spa-router/active' ``` **After:** ```js import Router from '@keenmate/svelte-spa-router' import {link, location, querystring, routeParams} from '@keenmate/svelte-spa-router' import {wrap} from '@keenmate/svelte-spa-router/wrap' import {active} from '@keenmate/svelte-spa-router/active' ``` > **Note:** `params` is now named `routeParams` for clarity. ## Step 3: Convert Store Usage to Function Calls ### Location, Querystring, and Params **Before (Svelte 4):** ```svelte
Location: {$location}
Query: {$querystring}
Params: {JSON.stringify($params)}
``` **After (Svelte 5):** ```svelteLocation: {location()}
Query: {querystring()}
Params: {JSON.stringify(routeParams())}
``` > **Important:** Note `params` is now `routeParams` and called as a function. ### Reactive Statements If you're using stores in reactive statements: **Before (Svelte 4):** ```svelte ``` **After (Svelte 5):** ```svelte ``` Or use `$derived` rune: ```svelte ``` ## Step 4: Convert Event Handlers ### Router Events **Before (Svelte 4):** ```svelteID: {params.id}
``` **After (Svelte 5):** ```svelteID: {routeParams.id}
``` > **Note:** The prop name is now `routeParams` (not `params`). ### Static Props from Router If using `wrap()` with static props: **Before (Svelte 4):** ```svelte ``` **After (Svelte 5):** ```svelte ``` ## Step 6: Update Store Subscriptions If you're subscribing to stores programmatically: **Before (Svelte 4):** ```js import {location} from 'svelte-spa-router' const unsubscribe = location.subscribe(value => { console.log('Location changed:', value) }) // Later unsubscribe() ``` **After (Svelte 5):** ```js import {location} from '@keenmate/svelte-spa-router' $effect(() => { console.log('Location changed:', location()) }) // Cleanup happens automatically when component is destroyed ``` ## Step 7: Check Actions Compatibility The `link` and `active` actions work the same way in both versions: ```svelte Link ``` No changes needed here! ## Step 8: Verify Route Guards Pre-conditions (route guards) work identically: ```js wrap({ asyncComponent: () => import('./Admin.svelte'), conditions: [ async (detail) => { // Your auth logic return true } ] }) ``` No changes needed! ## Common Patterns ### Pattern 1: Conditional Rendering Based on Location **Before (Svelte 4):** ```svelte {#if $location === '/'}ID: {$routeParams.id}
``` **✅ Fix:** ```svelteID: {routeParams().id}
``` Or better yet, use props in route components: ```svelteID: {routeParams.id}
``` ### Error: "params is undefined" **Cause:** The prop name changed from `params` to `routeParams`. **❌ Wrong:** ```javascript import { params } from '@keenmate/svelte-spa-router' ``` **✅ Fix:** ```javascript import { routeParams } from '@keenmate/svelte-spa-router' ``` ### Error: Event handlers not firing **Cause:** Event handler prop names changed to camelCase. **❌ Wrong:** ```svelte