Skip to content

Using resolve with hash router results in full-page reloads on every anchor click #14894

@gwennlbh

Description

@gwennlbh

Describe the bug

Basically, in Hash router mode, resolve() returns base + # + path, but this results in a full-page reload on every link.

Returning just # + path would work.

I guess you might actually need to have the base path sometimes, but enforcing resolve() usage on all <a href>s (thru the eslint rule) suggests that it's appropriate to use for most cases (and in most cases, you are already on the base path, so you only need to change the hash)

For that use case, I see multiple solutions

  • Add a separate function, sth like resolveFull, that maybe compile-time-errors if router is not in hash mode, to prevent confusion
  • Add an argument to resolve(), but the arg name would have to be a bit ugly in order to not conflict with any possible param name (sth like resolve("...", { "#withBase": false }), yeah, it's... not pretty lol)
  • Bring back base (but it was removed for a reason so this feels a bit backwards)
  • Don't change resolve(), but add a hash-router-only resolveHash() -- I wouldn't really like this one since it'd mean that switching to a hash router involves replacing (nearly) all resolve calls with resolveHash() calls, and it feels a bit asymmetric

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-isdeof9k?file=src%2Froutes%2FHeader.svelte

Note that you need to go to /base/, just /base results in a 404 (this might be Stackblitz-specific though)

Logs

System Info

System:
  OS: Linux 5.0 undefined
  CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Memory: 0 Bytes / 0 Bytes
  Shell: 1.0 - /bin/jsh
Binaries:
  Node: 20.19.1 - /usr/local/bin/node
  Yarn: 1.22.19 - /usr/local/bin/yarn
  npm: 10.8.2 - /usr/local/bin/npm
  pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
  @sveltejs/adapter-auto: ^7.0.0 => 7.0.0 
  @sveltejs/kit: ^2.48.4 => 2.48.4 
  @sveltejs/vite-plugin-svelte: ^6.2.1 => 6.2.1 
  svelte: ^5.41.0 => 5.43.3 
  vite: ^7.1.10 => 7.2.0

Severity

serious, but I can work around it

Additional Information

Workaround involves using another function instead of $app/paths' resolve. This requires disabling the lint rule though, since the function is not longer "the" resolve.

See cigaleapp/cigale@77b2039 for an example

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions