Home

Awesome

Svelte Router

version license

Router component for Svelte

This branch is for Svelte v3.0.0+. For usage with Svelte v1.8.0+, see the v2 branch. For usage with Svelte v1.8.0-, see the 0.1.x branch.

Installation

Using npm:

npm install --save svelte-router

Using yarn:

yarn add svelte-router

Examples

<div>
  <Link to="/">Home</Link>
  <Link to="/welcome">Welcome</Link>
  <div use:create></div>
</div>

<script>
  import SvelteRouter, { Link } from 'svelte-router'
  import Home from './Home.svelte'
  import Welcome from './Welcome.svelte'

  function create (node) {
    const router = new SvelteRouter({
      target: node,
      mode: 'hash',
      routes: [{
        path: '/',
        component: Home
      }, {
        path: '/welcome',
        component: Welcome
      }]
    })

    return {
      destroy () {
        router.destroy()
      }
    }
  }
</script>

<style>
  .router-link-active {
    color: red;
  }
</style>

API

SvelteRouter

Link

Contributors