What is the difference between link and Link from svelte-routing and when to use which?

Viewed 76

In svelte-routing there is the Link component (with an uppercase "L") and link as an action. From the description:

Link:

A component used to navigate around the application.

link

An action used on anchor tags to navigate around the application. You can add an attribute replace to replace the current entry in the history stack instead of adding a new one.

Despite the description I don't understand the difference, i.e. when would I use which one? Both ways seem to do the trick in letting me navigate within my application.

1 Answers

They seem to be simply alternatives. There also is a links action to affect multiple links at once.

The code documentation of the link action states:

/**
 * A link action that can be added to <a href=""> tags rather
 * than using the <Link> component.
 *

One undocumented advantage of the Link component seems to be that it will set aria-current automatically:

<a href="{href}" aria-current="{ariaCurrent}" on:click="{onClick}" {...props} {...$$restProps}>
  <slot></slot>
</a>
Related