{
  "id": "e35154ae17ae41cf55660406",
  "source": "solid:signals",
  "type": "github-document",
  "title": "use-location",
  "content": "---\ntitle: useLocation\nuse_cases: \u003e-\n  current url tracking, query parameters, pathname parsing, hash navigation,\n  location state access\ntags:\n  - location\n  - url\n  - pathname\n  - query\n  - hash\n  - state\nversion: \"1.0\"\ndescription: \u003e-\n  Access reactive URL information with useLocation - track pathname, query\n  strings, hash, and navigation state in your SolidJS app.\n---\n\nThe `useLocation` function provides information about the current URL, including pathname, query strings, hash, and navigation state.\n\n## Import\n\n```ts\nimport { useLocation } from \"@solidjs/router\";\n```\n\n## Type\n\n```ts\nconst useLocation: \u003cS = unknown\u003e() =\u003e Location\u003cS\u003e;\n\ninterface Location\u003cS = unknown\u003e extends Path {\n\tquery: SearchParams;\n\tstate: Readonly\u003cPartial\u003cS\u003e\u003e | null;\n}\n\ninterface Path {\n\tpathname: string;\n\tsearch: string;\n\thash: string;\n}\n```\n\n## Parameters\n\nNone.\n\n## Return value\n\n`useLocation` returns a reactive `Location` object containing the current URL information.\n\nThe `Location` object contains:\n\n### `pathname`\n\n**Type:** `string`\n\nThe path portion of the URL, beginning with a `/` and excluding the query string and hash.\n\n### `search`\n\n**Type:** `string`\n\nThe query string portion of the URL, including the leading `?` character if a parameter exists.\n\n### `hash`\n\n**Type:** `string`\n\nThe hash fragment of the URL, including the leading `#` character if a hash exists.\n\n### `state`\n\n**Type:** `Readonly\u003cPartial\u003cS\u003e\u003e | null`\n\nCustom state passed from [`useNavigate`](/solid-router/reference/primitives/use-navigate).\n\n### `query`\n\n**Type:** `SearchParams`\n\nA reactive object containing the parsed query parameters from the URL.\n\n## Examples\n\n### Basic usage\n\n```tsx\nimport { useLocation } from \"@solidjs/router\";\n\nfunction ProductFilter() {\n\tconst location = useLocation();\n\n\tconst category = () =\u003e location.query.category || \"all\";\n\tconst page = () =\u003e location.query.page || \"1\";\n\n\treturn (\n\t\t\u003cdiv\u003e\n\t\t\t\u003cp\u003e\n\t\t\t\tFiltering by: {category()}, Page {page()}\n\t\t\t\u003c/p\u003e\n\t\t\u003c/div\u003e\n\t);\n}\n```\n\n## Related\n\n- [`useNavigate`](/solid-router/reference/primitives/use-navigate)\n- [`useParams`](/solid-router/reference/primitives/use-params)\n- [`useSearchParams`](/solid-router/reference/primitives/use-search-params)",
  "url": "https://github.com/solidjs/solid-docs/blob/HEAD/src/routes/solid-router/reference/primitives/use-location.mdx",
  "metadata": {
    "path": "src/routes/solid-router/reference/primitives/use-location.mdx",
    "repo": "solidjs/solid-docs",
    "repo_url": "https://github.com/solidjs/solid-docs.git",
    "size": 2199,
    "source_type": "github"
  },
  "hash": "f95d9dbc0df6e95239bd9b0c3e8916dd49db08532a60e313e76f96567b0bd0a5",
  "timestamp": "2026-02-23T11:43:00.193065033+01:00"
}