use-router
Hooks to work with routes in the browser
Hook to handle routes based on expressions according to the https://github.com/uppercod/exp-route library, this hook is used by @atomico/components/router****

Module

1
import {
2
useRouter,
3
useRoute,
4
useRouteMatch,
5
useRedirect,
6
redirect,
7
getPath
8
} from "@atomico/hooks/use-router";
Copied!

useRouter syntax

1
const [ view, path, params, search ] = useRouter({
2
"/":()=><h1>home</h1>,
3
"user/{id}":({ id })=><my-user id={id}/>,
4
})
Copied!
Where:
  1. 1.
    view: return of the last function executed according to the route match.
  2. 2.
    path: string, represents the prop of the last path that consists of the path match.
  3. 3.
    params: parameters captured according to the path
  4. 4.
    search: parameters captured from the path

useRoute syntax

1
const [ view, path, params, search ] = useRoute("/",()=><h1>home</h1>);
Copied!
Share the return from useRouter

useRouteMatch syntax

1
const match = useRouteMatch();
2
3
const isHome = match("/home");
Copied!