1.3.2 • Published 9 years ago

router-rx v1.3.2

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

router-rx Build Status Dependencies Status npm version

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

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

1.3.2

9 years ago

1.3.1

9 years ago

1.3.0

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago