Add `goto` options to `Navigation` object and/or offer a way to alter a navigation in progress
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:
- Add an
optionsprop toNavigation, mirroringgoto.optionsstructure. - Add a
rewritefunction toBeforeNavigate, that basically doescancel+goto, and preserves all options
Alternatives considered
None
Importance
would make my life easier
Additional Information
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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