svelte-router

3.0.0-alpha.2 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i svelte-router

Weekly Downloads

15

Version

3.0.0-alpha.2

License

MIT

Unpacked Size

100 kB

Total Files

7

Last publish

Collaborators

  • jikkai