MCPcopy Index your code
hub / github.com/bluwy/svelte-router

github.com/bluwy/svelte-router @v0.5.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.5.0 ↗ · + Follow
73 symbols 160 edges 38 files 3 documented · 4%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Svelte Router

package version npm downloads ci

An easy-to-use SPA router for Svelte.

Comparison with other routers

Features

  • Super simple API
  • Support hash and path based navigation
  • Nested routes
  • Redirects and navigation guards (with async support)
  • Lazy loading routes
  • Auto base tag navigation

Not Supported

  • Server-side rendering (SSR) - Use Sapper instead
  • Relative navigations - Use absolute path and dynamic syntax instead

Quick Start

Install @bjornlu/svelte-router:

$ npm install @bjornlu/svelte-router

Define routes:

// main.js

import { initPathRouter } from '@bjornlu/svelte-router'
import App from './App.svelte'
import Home from './Home.svelte'

// Use `initHashRouter` for hash mode
initPathRouter([
  { path: '/', component: Home }
])

const app = new App({
  target: document.body
})

export default app

Render routes and links:



<script>
  import { RouterView, Link } from '@bjornlu/svelte-router'
</script>

<main>
  <nav>
    <Link to="/">Home</Link>
  </nav>
  <RouterView />
</main>

Done!

Documentation

Ready to learn more? The documentation is split into two parts:

  • Guide: Covers common usage to advanced topics
  • API reference: Covers the structure of the API

Examples

Contributing

All contributions are welcomed. Check out CONTRIBUTING.md for more details.

License

MIT

Extension points exported contracts — how you extend this code

MatchedRoute (Interface)
(no doc)
src/matcher.ts
LocationInput (Interface)
(no doc)
src/types.ts
Route (Interface)
(no doc)
src/router/base.ts
RouteMatchData (Interface)
(no doc)
src/matcher.ts
RouteRecord (Interface)
(no doc)
src/types.ts
LinkState (Interface)
(no doc)
src/router/base.ts

Core symbols most depended-on inside this repo

matchRoute
called by 9
src/matcher.ts
replace
called by 8
src/router/path-router.ts
formatPath
called by 5
src/util.ts
initPathRouter
called by 3
src/global.ts
initRouter
called by 3
src/global.ts
replacePathParams
called by 3
src/util.ts
joinPaths
called by 3
src/util.ts
push
called by 3
src/router/path-router.ts

Shape

Function 38
Method 20
Class 9
Interface 6

Languages

TypeScript100%

Modules by API surface

src/router/path-router.ts10 symbols
src/router/hash-router.ts10 symbols
src/util.ts9 symbols
src/router/base.ts8 symbols
src/matcher.ts7 symbols
src/global.ts5 symbols
examples/react-router/src/react/MyReactComponent.js4 symbols
scripts/cy-serve.js3 symbols
examples/react-router/rollup.config.js3 symbols
examples/lazy-loading/rollup.config.js3 symbols
examples/basic/rollup.config.js3 symbols
src/types.ts2 symbols

For agents

$ claude mcp add svelte-router \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page