feat: add optional params for hash and searchParams to resolve()

#14756

Closing issue

Pull request

Opened at Oct 19, 2025, 10:02 AM
C
codevogel
Oct 19, 2025, 10:02 AM

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 and helps address

  • 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.
👍 8🎉 4❤️ 11