Skip to content

Commit

Permalink
Update InertiaLink to use the "use:inertia" directive under the hood.
Browse files Browse the repository at this point in the history
  • Loading branch information
pedroborges committed Sep 25, 2020
1 parent 35be265 commit 8d88e82
Showing 1 changed file with 12 additions and 23 deletions.
35 changes: 12 additions & 23 deletions packages/inertia-svelte/src/Link.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<script>
import { Inertia, shouldIntercept } from '@inertiajs/inertia'
import { createEventDispatcher } from 'svelte'
const dispatch = createEventDispatcher()
import { inertia } from './'
export let
data = {},
Expand All @@ -13,26 +10,18 @@
preserveState = false,
only = [],
headers = {}
function visit(event) {
dispatch('click', event)
if (shouldIntercept(event)) {
event.preventDefault()
Inertia.visit(href, {
data,
method,
preserveScroll,
preserveState,
replace,
only,
headers
})
}
}
</script>

<a {...$$restProps} {href} on:click={visit}>
<a
use:inertia={{ ...$$props }}
{...$$restProps}
{href}
on:click
on:cancelToken
on:start
on:progress
on:finish
on:cancel
on:success>
<slot />
</a>

0 comments on commit 8d88e82

Please sign in to comment.