Skip to content

Add data-sveltekit-replace link option #9014

@axwalker

Description

@axwalker

Describe the problem

If you want create a navigation where the navigation history is replaced, you always have to use goto with the replace option instead of an <a> link.

This means you lose a few benefits:

  • The ability to middle-click or cmd+click to open the link in a new tab
  • easy preloading of code/data with their corresponding link options
    • instead you have to call preloadData/preloadCode within an on:click call before your goto call
    • if you want the preload call to happen on hover/tap instead, you need more handlers on top
  • easier a11y compliance -> instead should manually describe the role/purpose of the button (or whatever component is being used)
  • any automatic link scraping that you might have set up for SEO/sitemap generation/whatever else

Describe the proposed solution

An additional data-sveltekit-replace option on top of the existing options.

This would turn something like this:

<button
  on:click={() => goto('/my-path/123', { replaceState: true })}
  on:touchstart={() => preloadData('/my-path/123')}
  on:mousedown={() => preloadData('/my-path/123')}
>
  Go to page
</button>

into this:

<a href="/my-path/123" data-sveltekit-replace data-sveltekit-preload-data="tap">
  Go to page
</a>

Alternatives considered

Using goto as described above.

Importance

would make my life easier

Additional Information

A related comment was made in another somewhat related issue here.

I tried looking for other discussions on this feature and couldn't find any - sorry if I missed one!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions