Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jikkai/svelte-router

Router component for Svelte
https://github.com/jikkai/svelte-router

router router-component svelte

Last synced: about 1 month ago
JSON representation

Router component for Svelte

Awesome Lists containing this project

README

        

# Svelte Router

![version](https://img.shields.io/npm/v/svelte-router.svg)
![license](https://img.shields.io/github/license/mashape/apistatus.svg)

> Router component for Svelte

This branch is for Svelte v3.0.0+. For usage with Svelte v1.8.0+, see the [v2 branch](https://github.com/jikkai/svelte-router/tree/v2). For usage with Svelte v1.8.0-, see the [0.1.x branch](https://github.com/jikkai/svelte-router/tree/0.1.x).

## Installation

Using npm:

```bash
npm install --save svelte-router
```

Using yarn:

```bash
yarn add svelte-router
```

## Examples

```html


Home
Welcome

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()
}
}
}

.router-link-active {
color: red;
}

```

## 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

* [@rumpytim](https://github.com/rumpytim)
* [@RobBrazier](https://github.com/RobBrazier)
* [@stalkerg](https://github.com/stalkerg)