{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "shell-routing",
  "title": "Hash routing",
  "description": "Reads and sets the current route from the URL's hash, and splits a route into its path and query string.",
  "files": [
    {
      "path": "shell/routing.ts",
      "content": "import { useEffect, useState } from \"react\";\n\n// The root route where there is no location to read, as when a page renders\n// to markup on a server.\nfunction currentRoute(): string {\n  return typeof location === \"undefined\" ? \"/\" : location.hash.slice(1) || \"/\";\n}\n\n/**\n * Hash-based client-side routing. The URL's hash is the only source of\n * truth for which page is shown; a block reads it through `useRoute` and\n * moves it through `navigate`, and never touches `location` directly.\n */\nexport function useRoute(): string {\n  const [route, setRoute] = useState(currentRoute);\n  useEffect(() => {\n    const update = () => setRoute(currentRoute());\n    window.addEventListener(\"hashchange\", update);\n    return () => window.removeEventListener(\"hashchange\", update);\n  }, []);\n  return route;\n}\n\nexport function navigate(route: string) {\n  location.hash = route;\n}\n\n/**\n * Split a hash route into its path and decoded query parameters. The URL is\n * the only source of truth for a view: `useRoute` returns the full hash\n * including any `?query`, and only this function decides which part is the\n * page. Params are decoded once by URLSearchParams; the path never carries\n * the query.\n */\nexport function splitRoute(route: string): {\n  path: string;\n  query: URLSearchParams;\n} {\n  const at = route.indexOf(\"?\");\n  return {\n    path: at === -1 ? route : route.slice(0, at),\n    query: new URLSearchParams(at === -1 ? \"\" : route.slice(at + 1)),\n  };\n}\n",
      "type": "registry:block",
      "target": "@components/shell/routing.ts"
    }
  ],
  "type": "registry:block"
}