Code Monkey home page Code Monkey logo

Comments (3)

davidhorak avatar davidhorak commented on May 24, 2024

@yet-another-dev it is actually "cls" prop, https://github.com/spaceavocado/svelte-router#router-link-component, to pass the custom base class.

from svelte-router.

jaymakes11 avatar jaymakes11 commented on May 24, 2024

Ah, I see... Missed that in the docs.

Would it not be more intuitive/flexible to simply pass through all props (via {...$$props} documented here)

$$props references all props that are passed to a component – including ones that are not declared with export.

That would allow other attributes to pass through without having to manually handle them. It would also allow for not having to use a custom "class" attribute for passing through classes (which becomes unnecessarily verbose when using Pug, as it requires declaring the actual attribute rather than being able to use Put's dot syntax (e.g. RouterLink.navItem(to=")).

Looks like adding {...$$props} here should do the trick (though I haven't tested this yet):

<a
href="{to}"
class="{cssClass}"
class:disabled
on:click|preventDefault="{navigate}"
>

The only reason I can see to potentially not want to do this is due to the note on the docs that states:

It is useful in rare cases, but not generally recommended, as it is difficult for Svelte to optimize.

The "as it is difficult for Svelte to optimize" is the part that makes me think this might be undesired for some reason. But without knowing more about the details of the optimizations that this makes difficult for Svelte it's hard to say.

from svelte-router.

davidhorak avatar davidhorak commented on May 24, 2024

@yet-another-dev Using the $$props is definitely an option but it the case of the Link component is rather more safe from the perspective of shared library to have a limited, and documented, set of properties - which we might extend as needed by community.

Also, the link component should be more/less just a base link component, for any project specific needs it would be better to create a custom component with own props, or use the custom component as a wrapper of the shipped Link component.

from svelte-router.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.