3.0.0-alpha.2 • Published 5 years ago

svelte-router v3.0.0-alpha.2

Weekly downloads
18
License
MIT
Repository
github
Last release
5 years ago

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

  • push(path: string)
  • replace(path: string)
  • go(n: number)
  • goBack()
  • goForward()
  • listen(fn: function)

Link

  • to: string
  • replace: boolean
  • className: string
  • activeClassName: string

Contributors

3.0.0-alpha.2

5 years ago

3.0.0-alpha.1

5 years ago

3.0.0-alpha.0

5 years ago

2.0.0-beta.1

6 years ago

2.0.0-beta.0

6 years ago

1.8.1

6 years ago

1.8.0

6 years ago

1.7.0

6 years ago

1.6.0

6 years ago

1.5.0

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.1.0

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago