# @maxima/a-router

> Simple frontend routing library for React using TypeScript & React hooks.

Latest version **0.0.16** (published 2022-05-05) · GPL-3.0-only license · 0 weekly downloads

## Install

```sh
npm install @maxima/a-router
pnpm add @maxima/a-router
yarn add @maxima/a-router
bun add @maxima/a-router
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.16 |
| Published | 2022-05-05 |
| First published | 2019-08-15 |
| Weekly downloads | 0 |
| License | GPL-3.0-only |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 64.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | hck |
| Maintainers | alexsvirin |

## Links

- npm: https://www.npmjs.com/package/@maxima/a-router
- npm.io page: https://npm.io/package/@maxima/a-router

## Dependencies (1)

- [qs](https://npm.io/package/qs.md) ^6.7.0

## Recent versions

- 0.0.16 (latest) — 2022-05-05
- 0.0.15 — 2021-02-12
- 0.0.14 — 2021-01-27
- 0.0.13 — 2020-12-18
- 0.0.12 — 2020-12-18
- 0.0.11 — 2020-11-23
- 0.0.10 — 2020-07-31
- 0.0.9 — 2020-05-07
- 0.0.8 — 2020-02-18
- 0.0.7 — 2020-02-18
- 0.0.6 — 2019-11-05
- 0.0.5 — 2019-10-01
- 0.0.4 — 2019-09-02
- 0.0.3 — 2019-08-20
- 0.0.2 — 2019-08-20
- … 1 more at https://npm.io/package/@maxima/a-router/versions

## README

# ARouter

Simple frontend routing library for React using TypeScript & React hooks.

## How to install

```shell
yarn install a-router
```

## How to use

```typescript
const Sample: React.SFC<{}> = (props) => {
  const routes = [
    { path: '/', component: RootComponent },
    { path: '/entries', component: EntriesComponent },
    { path: '/entries/:id(.:format)', component: EntryDetailsComponent, constraints: { id: /\d+/, format: /html|json/ } }
  ];

  return useRoutes(routes);
};
```

## API

### RouterLocation

* `pathname: string` - location pathname
* `search: string` - search part of the location url
* `hash: string` - hash part of the location url
* `queryParams: { [key: string]: any }` - object representing extracted query parameters

### Route

* `path: string` - route path which will be matched against current location
* `constraints?: { [key: string]: RegExp }` - route constraints (object with parameter names and regular expressions as constraints)
* `exact?: boolean` - flag which indicates whether route path should match current location exactly or not
* `component: React.ComponentType<{ match: T | undefined; location: RouterLocation; }>` - component to be rendered for this route

### useRoutes hook params

* `routes: Array<Route<any>>` - array of routes to match against router location

### usePrompt hook params

* `visible: boolean` - flag which indicates whether navigation to other paths/locations has to be blocked or not
* `message: string` - message to show when the navigation is blocked and user still tried to navigate to other path/location

### useRedirect hook params

* `from: string` - redirect source path
* `to: string` - redirect destination path

### List of props available in route components

* `match: T | undefined` - list of query parameters matched for the route
* `location: RouterLocation` - current router location

## Licence

GPLv3

Copyright hck, 2019

---
_Source: https://npm.io/package/@maxima/a-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
