From d6fae42dc35abecdb530d925fe74fefe4fdc5187 Mon Sep 17 00:00:00 2001 From: Jacob Marshall Date: Mon, 13 Jan 2025 17:41:31 +0000 Subject: [PATCH] docs: Add useRouter Documentation (#325) --- .../routes/documentation/hooks/use-router.mdx | 38 ++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/apps/documentation/src/routes/documentation/hooks/use-router.mdx b/apps/documentation/src/routes/documentation/hooks/use-router.mdx index 134cd5cf..0d26ac44 100644 --- a/apps/documentation/src/routes/documentation/hooks/use-router.mdx +++ b/apps/documentation/src/routes/documentation/hooks/use-router.mdx @@ -11,4 +11,40 @@ import Breadcrumbs, { Element } from '@/components/breadcrumbs' # useRouter -TODO +The `useRouter` hook provides access to various data about the current route, as well as methods to navigate between pages, as seen in the below example: + +```typescript jsx +import { useRouter } from 'tuono' + +export default function IndexPage() { + const router = useRouter() + + return ( + <> +

pathname: {router.pathname}

+ + + ) +} +``` + +## `router` object + +- `pathname`: `string` - Returns the current path name +- `query`: `Record` - This object contains all the query params of the current route + +The following methods are included inside `router`: + +### `router.push` + +Handles client side page navigation quickly. Useful for internal links, or for when you need to change url in some JS. + +```ts +router.push(path, options) +``` + +- `path`: `string` - The path of the page you want to navigate to +- `options`: `PushOptions` - Optional config object for additional control + - `scroll`: `boolean` - If `false` the scroll offset will be kept across page navigation. Default `true`