npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

svelte5-router-spa

v0.1.5

Published

`npm i svelte5-router-spa`

Readme

Svelte5 router for SPA

npm i svelte5-router-spa

Svelte 5 router for Single Page Applications (SPA). It uses route-recognizer for flexible path matching and supports asynchronous component loading.

Usage

1. Define your routes

Routes are defined as an object where keys are paths and values are RoutingFunction. A RoutingFunction can be asynchronous and should return an object with component and props.

// routes.ts
import type { Route } from "svelte5-router-spa";
import Home from "./components/Home.svelte";

export const routes: Route = {
    "/": async () => {
        // You can fetch data or dynamic import components here
        return {
            component: Home,
            props: { title: "Welcome Home" }
        };
    },
    "/user/:id": async (params) => {
        const { id } = params;
        const UserProfile = (await import("./components/UserProfile.svelte")).default;
        return {
            component: UserProfile,
            props: { userId: id }
        };
    }
};

2. Use the Router component

Place the Router component in your main application file (e.g., App.svelte).

<script lang="ts">
    import { Router } from "svelte5-router-spa";
    import { routes } from "./routes";
</script>

<Router route={routes} />

3. Navigation

You can use the provided navigation utilities to move between pages.

<script lang="ts">
    import { navigation } from "svelte5-router-spa";
    const { goto } = navigation;

    function navigate() {
        goto("/home");
    }
</script>

<button onclick={navigate}>Go Home</button>

Automatic Anchor Handling

To automatically handle standard <a> tags for SPA navigation, use setupLink in your root layout or entry point.

<script lang="ts">
    import { onMount } from "svelte";
    import { navigation } from "svelte5-router-spa";

    onMount(() => {
        navigation.setupLink();
    });
</script>

API

Router Props

| Prop | Type | Description | | --- | --- | --- | | route | Route | Required. The route configuration object. | | errorComponent | Component | Optional. Component to show for 404 or 500 errors. | | loadingComponent | Component | Optional. Component to show while a route is being resolved. |

Navigation Utilities (navigation)

  • goto(url: string, data?: any): Navigate to a new URL.
  • pushState(data: any, url: string): Wrapper for history.pushState.
  • replaceState(data: any, url: string): Wrapper for history.replaceState.
  • setupLink(): Adds a global click listener to handle same-origin <a> tags automatically.
  • cleanupLink(): Removes the global click listener.

Types

Route

An object mapping paths to RoutingFunction.

RoutingFunction

(params?: Params) => MaybePromise<{ component: Component, props: any }> A function that receives URL parameters and returns (optionally as a Promise) the component and its props to render.