Router component for Svelte
This branch is for Svelte v1.8.1+. For usage with Svelte v1.8.0-, see the 0.1.x branch.
Using npm:
npm install --save svelte-router
Using yarn:
yarn add svelte-router
<div>
<RouterLink to="/">Home</RouterLink>
<RouterLink to="/welcome">Welcome</RouterLink>
<div id="app"></div>
</div>
<script>
import { Store } from 'svelte/store'
import SvelteRouter from 'svelte-router'
import Home from './Home.html'
import Welcome from './Welcome.html'
import Animal from './Animal.html'
const router = new SvelteRouter({
mode: 'hash',
routes: {
'/': Home,
'/welcome': Welcome,
'/animal': {
Component: Animal,
props: {
store: new Store({
animal: 'dog',
sheep: 'baaah',
moo: {
cow: true,
foo: 'bar'
}
}),
data: {
qwert: 'asdf'
}
}
}
}
})
export default {
oncreate () {
router.create('#app')
},
ondestroy () {
router.destroy()
},
components: {
RouterLink: SvelteRouter.RouterLink
}
}
</script>
<style>
.router-link-active {
color: red;
}
</style>
push(path: string)
replace(path: string)
go(n: number)
listen(fn: function)
replace
: booleanmatch
: string