Skip to content

Commit

Permalink
docs: Add useRouter Documentation (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobhq authored Jan 13, 2025
1 parent 0db1245 commit d6fae42
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion apps/documentation/src/routes/documentation/hooks/use-router.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<p>pathname: {router.pathname}</p>
<button onClick={() => router.push("/foo")}>
My link
</button>
</>
)
}
```
## `router` object
- `pathname`: `string` - Returns the current path name
- `query`: `Record<string, unknown>` - 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`

0 comments on commit d6fae42

Please sign in to comment.