feat: allow resolve() to accept pathnames with query strings and hash fragments
#15458
Closing issues
Describe the bug
This is fine:
This should be fine, but is not:
Reproduction
Use the new resolve function with a query string parameter in the first parameter's string.
Logs
System Info
npx envinfo --system --npmPackages svelte,rollup,webpack --binaries --browsers
System:
OS: macOS 15.5
CPU: (8) arm64 Apple M2
Memory: 227.25 MB / 16.00 GB
Shell: 3.7.1 - /Users/m/.local/share/devbox/global/default/.devbox/nix/profile/default/bin/fish
Binaries:
Node: 22.14.0 - ~/projects/github/pipestack/webapp/main/.devbox/nix/profile/default/bin/node
npm: 10.9.2 - ~/projects/github/pipestack/webapp/main/.devbox/nix/profile/default/bin/npm
Browsers:
Brave Browser: 137.1.79.118
Chrome: 138.0.7204.184
Safari: 18.5
npmPackages:
svelte: ^5.37.3 => 5.37.3
Severity
blocking an upgrade of svelte
Describe the problem
For internal navigation, I tend to use goto().
The lint rule svelte/no-navigation-without-resolve triggers when calling goto() without wrapping the path in resolve().
However, since resolve() currently only accepts plain /route or /route/[slug] URLs, it's not possible to use goto() with URLs that include a hash or search parameters. Or at least, not without triggering that linting rule.
e.g. this throw the linting rule for both the a tag and the button
<script lang="ts">
import { goto } from "$app/navigation";
import { resolve } from "$app/paths";
const myURL = resolve('/my-page') + '#some-hash';
</script>
<a href={myURL}>My A Tag</a>
<button onclick={() => { goto(myURL) }}>My Button</button>
If we try to apply the tag inside the resolve() function:
<script lang="ts">
import { goto } from "$app/navigation";
import { resolve } from "$app/paths";
</script>
<a href={resolve('/my-page#some-hash')}>My A Tag</a>
<button onclick={() => { goto(resolve('/my-page#some-hash')) }}>My Button</button>
We get a type mismatch, which is pretty much the point of the resolve() function:
error| Argument of type '["/my-page#some-hash"]' is not assignable to parameter of type '[route: "/"] | [route: "/my-page"] | [route: "/my-page/"]'. Type '["/my-page#some-hash"]' is not assignable to type '[route: "/my-page/"]'. Type '"/my-page#some-hash"' is not assignable to type '"/my-page/"'.
I've tried several workarounds, including string interpolation and concatenation, but these approaches also trigger the lint rule.
Note: The playground doesn’t actually run SvelteKit, so resolve() doesn’t throw typing errors there as it would locally. There's no /routes/my-page/+page.svelte, but <a href={resolve(hashedSvelteURL)}>my svelte link</a> is still accepted as “valid”.
Currently, the only way to navigate to unresolved or partially resolved paths is via window.location.href, which makes sense since it's intended for external URLs.
However, since linking to fragments like /projects#project-slug is common (and even used throughout the Svelte docs), it seems odd that resolve() doesn’t support searchParams or hash values.
So unless I’m missing something, the only two options at the moment are:
- ignore the lint rule, or
- use
window.location.hreffor internal navigation.
Alternatives considered
I searched for documentation or existing discussions on how to handle this within the current linting constraints but couldn’t find any.
If a workaround already exists, perhaps the resolve documentation could be updated to include guidance or examples.
Would you like me to make it sound slightly more “formal” (to match typical framework issue tone), or keep this slightly conversational GitHub style?
Describe the proposed solution
resolve() already supports a slug parameter.
It would be helpful if it also accepted optional arguments like:
resolve(path, { hash?: string, searchParams?: Record<string, string> })
These additions wouldn’t break existing functionality and would make internal navigation with anchors or query parameters lint-compliant.
Implementation-wise, resolve() could run its existing logic first and then append the hash and/or serialized searchParams', similar to how SvelteURL` appends these.
Alternatives considered
I searched for documentation or existing discussions on how to handle this within the current linting constraints but couldn’t find any.
If a workaround already exists, perhaps the resolve documentation could be updated to include a pointer to this workaround.
Alternative solutions would be:
-
Relax the linting rule to allow strings that append hashes or search parameters. However, this feels undesirable, since it’s much cleaner to define hash and searchParams programmatically—similar to how SvelteURL handles them—rather than relying on string interpolation.
-
Add built-in
resolve()support for SvelteURL, so that we could call something likegoto(mySvelteURL.resolve()). -
Allow
resolve()to take inSvelteURL, and resolve it from there. This might even be the 'prettiest' option. This would probably need extra work soSvelteURLcan be expanded with a.slugattribute.
Importance
would make my life easier
Additional Information
No response
Pull request
Summary
Adds a ResolvablePath type that extends Pathname with optional ?${string} and #${string} suffixes, allowing resolve() to accept pathnames with query strings and hash fragments.
- No runtime changes —
resolve_route()already passes through?and#correctly Pathnametype is unchanged (still used forpage.url.pathname)- Existing
resolve()behavior with route IDs and params is unaffected
Motivation
Currently there is no way to use goto() with query strings or hash fragments without either disabling the lint rule or bypassing resolve():
resolve('/products?page=2')fails type-checking (Pathnamedoesn't include?)goto(resolve('/products') + '?page=2')fails thesvelte/no-navigation-without-resolvelint rule (argument isn't aresolve()call)
Per @teemingc's suggestion in #14750:
"It should be possible to add a union type with a template string such as
/my-route#${string}and/my-route?${string}. This would continue to keep the function type-safe."
This is a minimal type-only fix that doesn't conflict with #14756 (which adds richer { hash, searchParams } options).
What this enables
// All of these now type-check AND satisfy the lint rule:
goto(resolve('/products?page=2'));
goto(resolve(`/search?${params}`));
goto(resolve('/docs/intro#getting-started'));
Test plan
-
pnpm checkpasses -
pnpm lintpasses - Existing tests pass (no runtime changes, only type widening)
Closes #14750
🦋 Changeset detected
Latest commit: 977191d
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @sveltejs/kit | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
I love this, but it's missing one crucial bit. Because this only applies to pathnames, it means you can't do this:
resolve('/[slug]?foo=bar', { slug: 'banana' });...because route parameter notation like this falls under the
RouteIdtype. I think I'd prefer if the?{string}and#{string}variants applied to theRouteIdversion as well, though... that might be challenging. want to give it a crack?
Would that also be something like:
export type RouteIdWithSearchOrHash = RouteId |
`${RouteId}?${string}` |
`${RouteId}#${string}`Yeah I think so, but I'm not sure how it would affect our ability to extract the types of the route parameters for the second argument...
Yeah I think so, but I'm not sure how it would affect our ability to extract the types of the route parameters for the second argument...
The contributed solution really is quite brilliant 😄 https://github.com/sveltejs/kit/pull/15458/changes#diff-ca363a5801bb1240cce13fcdf36af610cfa8d5aae2007e77244a0d91f9ce5b4dR8-R12 I've tested it along with params that have matchers and it works well!
feat: allow resolve() to accept pathnames with query strings and hash fragments
• Feb 28, 2026, 8:41 PM- Add `ResolvablePath` type: `Pathname | ${Pathname}?${string} | ${Pathname}#${string}`
- Update `resolve()` and `resolveRoute()` signatures to accept `ResolvablePath`
- No runtime changes needed — `resolve_route()` already passes through `?` and `#`
- Enables `goto(resolve('/products?page=2'))` to satisfy both type checker and `svelte/no-navigation-without-resolve` lint rule
Closes #14750fix: update remaining resolve() signatures to use ResolvablePath
• Feb 28, 2026, 9:08 PM- Update resolve() in types/index.d.ts (was still using Pathname) - Update JSDoc template in client.js
- Rename ResolvablePath to PathnameWithSearchOrHash
- Remove redundant ${Pathname}?${string}#${string} variant
- Add RouteIdWithSearchOrHash type so resolve('/[slug]?foo=bar', { slug: 'banana' }) works
- Update ResolveArgs to extract params from RouteId with search/hash suffix
- Shorten changeset text