pateketrueke / yrv

Your routing vibes! (for Svelte)
https://svelte.dev/repl/0f07c6134b16432591a9a3a0095a80de
161 stars 9 forks source link

Support on:click for Link(button) without href #56

Closed ZerdoX-x closed 3 years ago

ZerdoX-x commented 3 years ago

Started from here: https://github.com/pateketrueke/yrv/issues/47

ZerdoX-x commented 3 years ago

So button is disabled if no link passed. I guess it's not good because Link (with tag) without href passed works well

ZerdoX-x commented 3 years ago

Workaround — pass disabled prop with "false" value: <Link button on:click="{() => alert(1)}" disabled="{false}">...</Link>

pateketrueke commented 3 years ago

Interesting, buttons are disabled if they're active, because they are used to navigate, the same as for regular links: it won't trigger the same action twice, hence the disabled attribute on buttons.

IMHO I would not use links or buttons if they're not for navigation, probably I'll remove the example too as it leads to unwanted behaviors.

The intention of allowing buttons as links, is not to behave as buttons, but trigger navigation changes when they're clicked, so they can't be opened away (right click on links) — check the demo page, I'm using a button link there, that gets disabled as soon its route is active, but enabled again when the route is different: if you click the button you go back then, etc.