# @chialab/router

> A simple agnostic router for Web Apps.

Latest version **3.0.2** (published 2022-04-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @chialab/router
pnpm add @chialab/router
yarn add @chialab/router
bun add @chialab/router
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.2 |
| Published | 2022-04-12 |
| First published | 2017-04-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 289.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Chialab |
| Maintainers | chialab-admin |
| Keywords | Chialab, route |

## Links

- npm: https://www.npmjs.com/package/@chialab/router
- Repository: git@github.com:Chialab/router-js
- Homepage: https://github.com/Chialab/router-js#readme
- Issues: https://github.com/Chialab/router-js/issues
- npm.io page: https://npm.io/package/@chialab/router

## Dependencies (1)

- [@chialab/proteins](https://npm.io/package/@chialab/proteins.md) ^3.0.0

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 3.0.2 (latest) — 2022-04-12
- 3.0.1 — 2019-11-15
- 3.0.0 — 2018-07-13
- 3.0.0-alpha.1 — 2018-02-27
- 1.0.1 — 2017-04-05
- 1.0.0 — 2017-04-05

## README

<p align="center">
    <strong>Router</strong> • A simple agnostic Router for Web Apps.
</p>

<p align="center">
    <a href="https://www.chialab.io/p/router-js"><img alt="Documentation link" src="https://img.shields.io/badge/Docs-chialab.io-lightgrey.svg?style=flat-square"></a>
    <a href="https://github.com/chialab/router-js"><img alt="Source link" src="https://img.shields.io/badge/Source-GitHub-lightgrey.svg?style=flat-square"></a>
    <a href="https://www.chialab.it"><img alt="Authors link" src="https://img.shields.io/badge/Authors-Chialab-lightgrey.svg?style=flat-square"></a>
    <a href="https://www.npmjs.com/package/@chialab/router"><img alt="NPM" src="https://img.shields.io/npm/v/@chialab/router.svg?style=flat-square"></a>
    <a href="https://github.com/chialab/router-js/blob/master/LICENSE"><img alt="License" src="https://img.shields.io/npm/l/@chialab/router.svg?style=flat-square"></a>
</p>

---

## Install

```sh
$ npm install @chialab/router
# or
$ yarn add @chialab/router
```

Use via cdn:
```html
<script type="text/javascript" src="https://unpkg.com/@chialab/router-js"></script>
```

## Example

```js
import Router from '@chialab/router';

const appRouter = new Router();
appRouter.on('/user/:username', function(id) {
    fetchUserById(id);
});
appRouter.on('/posts/:id', function(id) {
    fetchPostById(id);
});
appRouter.on('/posts', function() {
    listPosts();
});
appRouter.on('*', function() {
    page404();
});
appRouter.start();
```

---

## Development

[![Build status](https://github.com/chialab/router-js/workflows/Main/badge.svg)](https://github.com/chialab/router-js/actions?query=workflow%3ABuild)
[![codecov](https://codecov.io/gh/chialab/router-js/branch/master/graph/badge.svg)](https://codecov.io/gh/chialab/router-js)


### Requirements

In order to build and test Router, the following requirements are needed:
* [NodeJS](https://nodejs.org/) (>= 10.0.0)
* [Yarn](https://yarnpkg.com)
* [RNA](https://github.com/chialab/rna-cli) (>= 3.0.0)

### Build the project

Install the dependencies and run the `build` script:
```
$ yarn install
$ yarn build
```

This will generate the UMD and ESM bundles in the `dist` folder, as well as the declaration file.

### Test the project

Run the `test` script:

```
$ yarn test
```

---

## License

Router is released under the [MIT](https://github.com/chialab/router-js/blob/master/LICENSE) license.

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