mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-04 04:23:02 +00:00
update
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"id": "b81b658804b19aad5335d9e7",
|
||||
"source": "solid:signals",
|
||||
"type": "github-document",
|
||||
"title": "use-navigate",
|
||||
"content": "---\ntitle: useNavigate\nuse_cases: \u003e-\n programmatic navigation, redirects, auth flows, form submissions, history\n manipulation\ntags:\n - navigate\n - redirect\n - programmatic\n - history\n - state\nversion: \"1.0\"\ndescription: \u003e-\n Navigate programmatically with useNavigate - redirect users, handle auth\n flows, and control navigation with replace and scroll options.\n---\n\nThe `useNavigate` function provides a function for programmatically navigating to a new route.\n\n## Import\n\n```ts\nimport { useNavigate } from \"@solidjs/router\";\n```\n\n## Type\n\n```ts\ninterface NavigateOptions\u003cS = unknown\u003e {\n\tresolve: boolean;\n\treplace: boolean;\n\tscroll: boolean;\n\tstate: S;\n}\n\nfunction useNavigate(): (\n\tto: string,\n\toptions?: Partial\u003cNavigateOptions\u003e\n) =\u003e void;\nfunction useNavigate(delta: number): void;\n```\n\n## Parameters\n\n`useNavigate` takes no arguments.\n\n## Return value\n\n- **Type:** `(to: string | number, options?: NavigateOptions) =\u003e void | (delta: number) =\u003e void`\n\nReturns a function that accepts two arguments:\n\n### `to`\n\n- **Type:** `string | number`\n- **Required:** Yes\n\nThe target destination.\n\n- `string`:\n A path to navigate to.\n- `number`:\n A history delta (e.g., `-1` for back, `1` for forward).\n If provided, the `options` argument is ignored.\n\n### `options`\n\n- **Type:** `NavigateOptions`\n- **Required:** No\n\nConfiguration object for the navigation.\n\n#### `resolve`\n\n- **Type:** `boolean`\n- **Default:** `true`\n\nResolves the path relative to the current route.\nIf `false`, the path is resolved against the root (`/`).\n\nIf `to` is a query-only string (e.g., `?sort=asc`), this defaults to `false` to preserve the current pathname.\n\n#### `replace`\n\n- **Type**: `boolean`\n- **Default**: `false`\n\nReplaces the current history entry instead of adding a new one.\nUsed for redirects or state updates to prevent the user from navigating back to the previous state.\n\n#### `scroll`\n\n- **Type**: `boolean`\n- **Default**: `true`\n\nScrolls the window to the top after navigation.\n\n- `true`:\n Scrolls to the top or to the element matching the hash.\n- `false`:\n Maintains the current scroll position (unless a hash matches).\n\n#### `state`\n\n- **Type**: `any`\n- **Default**: `undefined`\n\nArbitrary state stored in `history.state`.\nThis value is accessible via `useLocation().state`.\n\nState is serialized using the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm), which supports most built-in types but not functions or DOM nodes.\n\n## Examples\n\n### Basic usage\n\n```tsx\nimport { useNavigate } from \"@solidjs/router\";\n\nconst navigate = useNavigate();\n\nnavigate(\"/users/123\");\n```\n\n### With `replace`\n\n```tsx\nimport { useNavigate } from \"@solidjs/router\";\n\nconst navigate = useNavigate();\n\n// Redirect (replace history)\nfunction login() {\n\tnavigate(\"/dashboard\", { replace: true });\n}\n```\n\n### With `delta`\n\n```tsx\nimport { useNavigate } from \"@solidjs/router\";\n\nconst navigate = useNavigate();\n\n// Go back one page\nfunction goBack() {\n\tnavigate(-1);\n}\n```\n\n### With `state`\n\n```tsx\nimport { useNavigate } from \"@solidjs/router\";\n\nconst navigate = useNavigate();\n\n// Pass custom state\nnavigate(\"/checkout\", {\n\tstate: { from: \"cart\", total: 100 },\n});\n```\n\n## Related\n\n- [useLocation](/solid-router/reference/primitives/use-location)\n- [redirect](/solid-router/reference/response-helpers/redirect)",
|
||||
"url": "https://github.com/solidjs/solid-docs/blob/HEAD/src/routes/solid-router/reference/primitives/use-navigate.mdx",
|
||||
"metadata": {
|
||||
"path": "src/routes/solid-router/reference/primitives/use-navigate.mdx",
|
||||
"repo": "solidjs/solid-docs",
|
||||
"repo_url": "https://github.com/solidjs/solid-docs.git",
|
||||
"size": 3364,
|
||||
"source_type": "github"
|
||||
},
|
||||
"hash": "100f26fc8828d2c39aea7bee2994faf747ce29c6095739bcbd505c22018e4b11",
|
||||
"timestamp": "2026-02-23T11:43:00.193145114+01:00"
|
||||
}
|
||||
Reference in New Issue
Block a user