Minimalist Svelte action to simply inject an active
class into route-matched links. Styling is up to you!
<script>
import { navlink } from 'svelte-navlink-action'
</script>
<!-- MARKUP -->
<ul>
<li><a href="/" use:navlink={{ exact: true }}>Home</a></li>
<li><a href="/foo" use:navlink>Foo (and children)</a></li>
<li><a href="/foo" use:navlink={{ exact: true }}>Foo (exact)</a></li>
<li><a href="/foo/1" use:navlink>foo/1</a></li>
<li><a href="/foo/2" use:navlink>foo/2</a></li>
<li><a href="/foo/3" use:navlink>foo/3</a></li>
</ul>
<!-- STYLES -->
<!-- alternatively just add the appropriate .active class styles to an imported stylesheet -->
<style>
a:global(.active) {
color: red;
}
</style>
use:navlink
|| use:navlink={{ exact?: boolean = false }}
Name | Type(s) | Default | Description |
---|---|---|---|
exact |
boolean |
false | Requires an exact url match if set to true, otherwise will match off the base-path of the url. |