You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: allow resolve() to accept pathnames with query strings and hash fragments (#15458)
## 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
- `Pathname` type is unchanged (still used for `page.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()`:
1. `resolve('/products?page=2')` fails type-checking (`Pathname` doesn't
include `?`)
2. `goto(resolve('/products') + '?page=2')` fails the
`svelte/no-navigation-without-resolve` lint rule (argument isn't a
`resolve()` 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
```js
// 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
- [x] `pnpm check` passes
- [x] `pnpm lint` passes
- [x] Existing tests pass (no runtime changes, only type widening)
Closes#14750
---------
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
* Resolve the URL of an asset in your `static` directory, by prefixing it with [`config.kit.paths.assets`](https://svelte.dev/docs/kit/configuration#paths) if configured, or otherwise by prefixing it with the base path.
0 commit comments