Skip to content

Conversation

@codevogel
Copy link

@codevogel codevogel commented Oct 19, 2025

Please go easy on me as this is the first PR I'm making to this repository, I am more than open to any suggested changes. I've been trying to get some help with this PR from the official Discord server, but discussion was pretty stale. So I'm hoping by opening this PR we can get this change going. Or, if the conclusion is 'we shouldnt do this at all', that's fine too!

Adds optional arguments for URL params hash and searchParams to resolve(). Appends these to the returned URL after resolving the path.

Resolves #14750 and helps address sveltejs/eslint-plugin-svelte#1353

  • Additionally updates the example docstring to show new usage:
import { resolve } from '$app/paths';

// using a pathname
const resolved = resolve(`/blog/hello-world`);

// using a route ID plus route parameters
const resolved = resolve('/blog/[slug]', {
	slug: 'hello-world'
});

// using a route ID plus URL parameters
const resolved = resolve('/blog/search',
	{ hash: 'results', searchParams: { author: 'John Doe', year: '2025' } }
});

// using a route ID plus route parameters and URL parameters
const resolved = resolve('/blog/[slug]',
	{ slug: 'hello-world' },
	{ hash: 'introduction' }
});

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
    • PR references an issue, but no discussion as of yet.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
    • I tried writing some tests in kit/packages/kit/test/apps/basics/test/client.test.js, but was met with ReferenceError: __SVELTEKIT_PAYLOAD__ is not defined at ../../../../src/runtime/app/paths/internal/client.js:1. This makes sense, because resolveRoute is used in resolve, which uses base, which needs __SVELTEKIT_PAYLOAD__. I wasn't able to find any existing tests for resolve or resolveRoute, other than at packages/kit/test/apps/options/test/test.js at line 97, which seems to be more of an integration test than actually testing resolveRoute itself.
      This is my first PR for this repo, so I'm not sure where below tests should go.
      Willing to add these if I get some pointers in the right direction.
    import { resolve } from '../../../../src/runtime/app/paths/client.js';
    
    describe('resolve function', () => {
       it('resolves a simple pathname', () => {
           const result = resolve('/blog/hello-world');
           expect(result).toBe('/blog/hello-world');
       });
    
       it('resolves a route ID with dynamic parameters', () => {
           const result = resolve('/blog/[slug]', { slug: 'hello-world' });
           expect(result).toBe('/blog/hello-world');
       });
    
       it('resolves a route ID with URL parameters', () => {
           const result = resolve('/blog/search', {
               hash: 'results',
               searchParams: { author: 'John Doe', year: '2025' }
           });
           expect(result).toBe('/blog/search?author=John%20Doe&year=2025#results');
       });
    
       it('resolves a route ID with both dynamic and URL parameters', () => {
           const result = resolve('/blog/[slug]', { slug: 'hello-world' }, { hash: 'introduction' });
           expect(result).toBe('/blog/hello-world#introduction');
       });
    
       it('handles empty parameters gracefully', () => {
           const result = resolve('/blog/[slug]', {});
           expect(result).toBe('/blog/[slug]');
       });
    });

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.
    • added a changeset as requested, but also somewhat unfamiliar with the 'correct' process for these, so a review is required.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@changeset-bot
Copy link

changeset-bot bot commented Oct 19, 2025

🦋 Changeset detected

Latest commit: 50af08d

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 Minor

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

@svelte-docs-bot
Copy link

*/
export type ResolveURLParams = {
hash?: string;
searchParams?: Record<string, string>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came to this PR from suffering from the huge eslint breakage due to this not being possible. 👍

I'd like to see this be at least searchParams?: Record<string, string> | URLSearchParams;.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would make sense. Happy to implement that too, I'm just a bit lost as to why the tests are failing.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kkarikos I implemented your suggestion!

@codevogel codevogel force-pushed the feat/optional-url-params-for-resolve branch 5 times, most recently from 751337e to da2e1b1 Compare October 23, 2025 15:42
Adds optional arguments for URL params `hash` and `searchParams` to
`resolve()`. Appends these to the returned URL after resolving the path.

Resolves sveltejs#14750 and helps address
sveltejs/eslint-plugin-svelte#1353

feat: make ResolveParams accept `searchParams: Record<string, string> | URLSearchParams | undefined`

fix: better arg parsing
@codevogel codevogel force-pushed the feat/optional-url-params-for-resolve branch from da2e1b1 to 6d27fae Compare October 23, 2025 15:44
@codevogel
Copy link
Author

Any pointers as to why svelte.dev / preview deployments fails?

When I try to see the details, I just get met with a 404 error in Vercel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add optional hash and searchParams arguments to resolve()

2 participants