sveltejs / sveltejs/kit

Add `goto` options to `Navigation` object and/or offer a way to alter a navigation in progress

Open
#11,585 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

I'm currently doing something very hacky because I cannot update the huge number of links on a page:

beforeNavigate(async ({ to, type, cancel }) => {
  if (
    (type === 'link' || type === 'goto') &&
    addTokenOnNavigation
  ) {
    const redirect = new URL(to.url);
    redirect.searchParams.set('token', data.token);
    cancel();             // Cancel original navigation
    await goto(redirect); // Navigate to the altered url
  }
});

This has many issues, but most importantly, there is no way to forward goto/link options such as noScroll/ data-sveltekit-noscroll.

Describe the proposed solution

Many solutions would solve my issue:

  1. Add an options prop to Navigation, mirroring goto.options structure.
  2. Add a rewrite function to BeforeNavigate, that basically does cancel+goto, and preserves all options
Alternatives considered

None

Importance

would make my life easier

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Navigation and BeforeNavigate APIs, then trace how goto and beforeNavigate handle link and goto navigations. Compare the proposed options property with the existing goto.options behavior and consider the rewrite alternative. Done means providing a decided API that preserves navigation options when the destination is altered, with coverage for the described token-injection case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.