@cloudflare/util-route-handler

Cloudflare Route Handler Util

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
@cloudflare/util-route-handler
Minified + gzip package size for @cloudflare/util-route-handler in KB

Readme

cf-util-route-handler

Cloudflare Route Handler Util

Installation

$ npm install cf-util-route-handler

Usage

import {handleRoutes, routeTo} from 'cf-util-route-handler';
import Backbone from 'backbone';

// setup the router
handleRoutes(function(url) {
  Backbone.history.navigate(url, true);
});

// do all the world to make the router work normally
new Backbone.Router({
  routes: {
    ''    : () => console.log('/'),
    hello : () => console.log('/hello'),
    world : () => console.log('/world')
  }
});
Backbone.history.start();

// start routing
routeTo('/');
routeTo('/hello');
routeTo('/world');

A handler looks like this:

handleRoutes(url => {
  takeActionWithUrl(url);
});

Only one handler is allowed to be setup.

routeTo is fire and forget, there's no callback for async transitions, and it does not return anything.

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.