
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
svelte-hash
Advanced tools
Easy URL hash management for Svelte.
svelte-hash provides a simple way to manage URL hash/fragment in Svelte.
[!NOTE] This library is client-side only, meaning SvelteKit (SSR) is not supported.
# Bun
bun i -D svelte-hash
# NPM
npm i -D svelte-hash
# Yarn
yarn add -D svelte-hash
# PNPM
pnpm add -D svelte-hash
[!TIP] It's really suggested to have a look to these interactive examples to test the library and understand the functionality (there you can see hash/fragment updates in the URL).
First of all, create and export a new hash store instance:
// store.ts
import { createHashStore } from 'svelte-hash'
interface Hash {
foo: string
bar: string
}
export const hash = createHashStore<Hash>()
[!NOTE]
- Explicitly defining the type of the hash is optional, but extremely suggested as it provides type checking and autocompletion
- Currently only string values are supported: this might change in a future major release
- Only one hash store can be initialized in the same project: multiple hash stores initialization will throw an error
Then, you can use the hash store in your components:
<!-- App.svelte -->
<script>
import { hash } from './store.ts'
// Prevent pushing to browser history every change with a "proxy" variable
// Every hash key could also not exist, so we need to provide a default value
let valueProxy = hash.foo || ''
</script>
<!-- The form will update the hash value only when submitted -->
<!-- result (on submit) will be: <URL>#foo={valueProxy} -->
<form on:submit|preventDefault={() => hash.foo = valueProxy}>
<input type="text" bind:value={valueProxy} />
<button type="submit">Submit</button>
</form>
<p>
To delete a hash key from the URL, you can set it to a falsy value:
import { hash } from './store.ts'
hash.foo = null
// or
hash.foo = undefined
// or
hash.foo = ''
The reason I created this library was to accomplish a simple URL hash/fragment management for my Svelte music player, Musicale (you should really check it out!).
I originally created the implementation directly in that project, but then I decided to extract it and make it a standalone library for everyone to use.
On the browser, to access the URL fragment you use window.location.hash, so I decided to take that for the library name.
We :heart: contributions!
Feel free to open an issue or a pull request but follow Contributing Guidelines.
If you don't know where to start, check out the help wanted issues!
GPL-3.0 License here.
FAQs
Easy URL hash management for Svelte.
We found that svelte-hash demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.