kit icon indicating copy to clipboard operation
kit copied to clipboard

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

Open GauBen opened this issue 2 years ago • 2 comments

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

GauBen avatar Jan 10 '24 16:01 GauBen

Somewhat related to #11223

GauBen avatar Jan 10 '24 16:01 GauBen

Just saw the new reroute hook! It won't work here as I want the edit to be visible in the address bar

GauBen avatar Jan 10 '24 17:01 GauBen