# use-router

Hook to handle routes based on expressions according to the [**https://github.com/uppercod/exp-route**](https://github.com/uppercod/exp-route) library, this hook is used by [**@atomico/components/router**](/doc/packages/atomico-components/keen-slider.md)\*\*\*\*

### Module

```javascript
import { 
    useRouter, 
    useRoute, 
    useRouteMatch, 
    useRedirect, 
    redirect, 
    getPath 
} from "@atomico/hooks/use-router";
```

### useRouter syntax

```jsx
const [ view, path, params, search ] = useRouter({
    "/":()=><h1>home</h1>,
    "user/{id}":({ id })=><my-user id={id}/>,
})
```

Where:

1. `view`: return of the last function executed according to the route match.
2. `path`: string, represents the prop of the last path that consists of the path match.
3. `params`: parameters captured according to the path
4. `search`: parameters captured from the path

### useRoute syntax

```jsx
const [ view, path, params, search ] = useRoute("/",()=><h1>home</h1>);
```

Share the return from useRouter

### useRouteMatch syntax

```jsx
const match = useRouteMatch();

const isHome = match("/home");
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://atomico.gitbook.io/doc/packages/atomico-hooks/use-router.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
