From 7a7ba8084ce01c7cf4f66a484acbce1203ca86af Mon Sep 17 00:00:00 2001 From: Omer Date: Wed, 16 Jun 2021 09:04:36 +0300 Subject: [PATCH] Can disable links with use:link (#163) Co-authored-by: Alessandro (Ale) Segala <43508+ItalyPaleAle@users.noreply.github.com> --- README.md | 26 +++++++++++++++++- Router.d.ts | 18 +++++++++++-- Router.svelte | 60 ++++++++++++++++++++++++++++++----------- test/app/src/App.svelte | 49 +++++++++++++++++++++++++++++++++ 4 files changed, 135 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index e34a074..bd74276 100644 --- a/README.md +++ b/README.md @@ -219,6 +219,8 @@ You can navigate between pages with normal anchor (``) tags. For example: Thus Spoke Zarathustra ```` +#### The `use:link` action + Rather than having to type `#` before each link, you can also use the `use:link` action: ````svelte @@ -228,7 +230,25 @@ import {link} from 'svelte-spa-router' The Little Prince ```` -You can also use the `use:link={variable}` action to have your link set to a variable and updated reactively (this will always take precedence over `href` attributes, if present): +The `use:link` action accepts an optional parameter `opts`, which can be one of: + +- A dictionary `{href: '/foo', disabled: false}` where both keys are optional: + - If you set a value for `href`, your link will be updated to point to that address, reactively (this will always take precedence over `href` attributes, if present) + - Setting `disabled: true` disables the link, so clicking on that would have no effect +- A string with a destination (e.g. `/foo`), which is a shorthand to setting `{href: '/foo'}`. + +For example: + +````svelte + + +The Biggest Princess +```` + +The above is equivalent to: ````svelte