# router-rx

> Router powered by Rx

Latest version **1.3.2** (published 2015-05-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install router-rx
pnpm add router-rx
yarn add router-rx
bun add router-rx
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.2 |
| Published | 2015-05-30 |
| First published | 2015-04-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gary Chambers |
| Maintainers | lipsmack |

## Links

- npm: https://www.npmjs.com/package/router-rx
- Repository: https://github.com/lipsmack/router-rx
- Issues: https://github.com/lipsmack/router-rx/issues
- npm.io page: https://npm.io/package/router-rx

## Dependencies (1)

- [rx](https://npm.io/package/rx.md) ^2.5.2

## Recent versions

- 1.3.2 (latest) — 2015-05-30
- 1.3.1 — 2015-05-05
- 1.3.0 — 2015-05-04
- 1.2.1 — 2015-05-01
- 1.2.0 — 2015-04-30
- 1.1.2 — 2015-04-27
- 1.1.1 — 2015-04-27
- 1.1.0 — 2015-04-16
- 1.0.2 — 2015-04-16
- 1.0.1 — 2015-04-16
- 1.0.0 — 2015-04-16

## README

# router-rx [![Build Status](https://travis-ci.org/lipsmack/router-rx.svg?branch=master)](https://travis-ci.org/lipsmack/router-rx) [![Dependencies Status](https://david-dm.org/lipsmack/router-rx.svg)](https://david-dm.org/lipsmack/router-rx) [![npm version](https://badge.fury.io/js/router-rx.svg)](http://badge.fury.io/js/router-rx)

A simple application router built around reactive principles.

_**Note:** router-rx currently only implements browser-based routing. Node.js routing to follow._

## Installation

`npm install router-rx`

## Usage

```javascript
import { createRouter, redirect } from "router-rx";
import { Disposable } from "rx";

const handler = function(id) {
    // Do something

    // Optional. Disposed on route change or tear down
    return Disposable.create(function() {
        // ...
    });
};

const router = createRouter({
    "/": redirect("/foo"),
    "/foo": handler,
    "/foo/:id": handler
});

// Tear down when finished
router.dispose();
```

## API

`Disposable createRouter( Object<String, Function> );`

Create a new router, mapping path strings to handler functions. Handler functions can optionally return an instance of `Rx.Disposable`, which will be automatically disposed when the route is changed or the containing router is disposed.

`Function redirect( String path, Boolean invoke );`

Create a handler function that redirects to a specified `path`. If `invoke` is true, the handler is called immediately.

`void useHistory( Boolean value );`

Enable/disable use of the HTML5 History API. router-rx uses hashChange by default and will only attempt to use the History API if it is supported.

## TODO

* Nested routers
* Node.js routing

## License

MIT

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