0.2.0 • Published 1 year ago

svelte-navlink-action v0.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

svelte-navlink-action

Version Bundle Size Build Status Open Issues

Discord GitHub Repo stars Twitter

Minimalist Svelte action to simply inject an active class into route-matched links. Styling is up to you!

Example

// Component.svelte
<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>

API

use:navlink || use:navlink={{ exact?: boolean = false }}

NameType(s)DefaultDescription
exactbooleanfalseRequires an exact url match if set to true, otherwise will match off the base-path of the url.
0.2.0

1 year ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago